solve my question shortly

Ads
 

solve my question shortly

<html>
<head>
<script>
function checkphoneNumber(number){ 
      if(/[^\d ]/.test(number)){
      alert('It should contain numbers [0-9] only!');
      document.getElementById("st").value="";
      return false;
      }
      if(number.substring(0,2)!="2,5"){
      alert("Number should begin with 2,5");
      document.getElementById("st").value="";
      return false;
      }
      if (number.length>10{
      alert("Invalid phone Number!It cannot exceeds the limit of 10 digits. ");
      document.getElementById("st").value="";
      return false;
    }
    return true;
}
</script>
</head>
<body>
Enter phone Number:&nbsp&nbsp&nbsp<input type="text" id="st" onkeyup="checkMobileNumber(this.value);">
</body>
</html>

this is a phone number validation but it s not working correctly,,,,, it have accept alphabetic character,,,so plze send me right code

View Answers

February 7, 2013 at 12:50 PM

you have done mistakes at many places such as in the textbox event you are calling the wrong method name than the method you have made in script, and there are some more syntactical errors also. I have corrected your errors now you can run your code easily. I have also made changes in the calling of your method i.e. in place of textbox event I have called it on form event i.e. onsubmit event.

The changed code is as follows :

<html>
<head>

<script>
function checkphoneNumber(number){
      //var num = number.value;
      if(/[^\d ]/.test(number)){
      alert('It should contain numbers [0-9] only!');      
      return false;
      } 
      if(number.substring(0,2)!="2,5"){
      alert("Number should begin with 2,5");      
      return false;
      }
      if(number.length > 10 || number.length < 10){
      alert("Invalid phone Number! Number must contain 10 digits. ");      
      return false;
    }
    return true;
}
</script>

</head>
<body>
<form action="#" onsubmit="checkphoneNumber(document.getElementById('st').value)">
Enter phone Number:   <input type="text" id="st">
<input type="submit" value="submit"/>
</form>
</body>
</html>

Ads









Related Tutorials/Questions & Answers:
solve my question shortly
solve my question shortly  <html> <head> <script> function checkphoneNumber(number){ if(/[^\d ]/.test(number)){ alert('It should contain numbers [0-9] only!'); document.getElementById
help me to solve this question...
help me to solve this question...  Given below is a class definition for Book. Type and compile the class, and answer the following questions: class Book { String title; //bookâ??s title double price; //bookâ??s
Advertisements
ArrayList question plz solve it
ArrayList question plz solve it  An arraylist object stores an Emp Object, where there is name,age,address of the employee is stored, And i want to access the data in the basis of age based? Provide answer to the question
plz solve my query?
plz solve my query?  how to remove all the options from select control in html using java script?   JavaScript remove all items <html> <script language="javascript" > function removeAllItems(selectbox
Solve my code
Solve my code  import javax.servlet.*; import javax.servlet.http.*; import java.sql.*; import java.io.*; public class ChangeDetails extends HttpServlet{ public void doPost(HttpServletRequest request,HttpServletResponse
help me to solve this question
help me to solve this question  Write a program that inputs a series of integers into an array. The numbers are in the range 0 to 100. Calculate and display : a) The Largest number b) The Smallest Number c)The sum of the numbers
help me to solve this question
help me to solve this question   A user needs to key in data into system in order to save data into array. The data are: a. Lecturer ID, Lecturer name, School, course code, course name, session, semester A user can edit the data
my question
my question   "Write a C/C++ program to show the stored procedure PROCRESETMAIL" on database "USER_NOTIFY
my question
my question   "Write a C/C++ program to show the stored procedure PROCRESETMAIL" on database "USER_NOTIFY
Check Digit Question not able to solve..
Check Digit Question not able to solve..   Hi, I need some help asap. I been stuck for this question for more than 3 days. Using Java. User needs to key in identification number (e.g. U0906931E) system check for the first
Please Help To Solve My Problem
Please Help To Solve My Problem  PHP I Have 6 Textbox and 1 ok button. 6 Textbox to Add the 6 Team Name. Each Team Name In String(Like- A,B,C,D,E,F... With B Team when A Team Play With B Team Again Then Generate Error. I Am Solve
plz help meto solve this question
plz help meto solve this question  for a file that exist what will be the length() method in the file class return
how do i solve this question?
how do i solve this question?  1.Define a class named Circle with the following properties: a) An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier
plz anyone can solve my
plz anyone can solve my  creat an applet prog which accepts the details of 10 customers like name , address , city , ect. and display it   import java.awt.*; import javax.swing.*; import java.awt.event.*; import
Small Bug How to solve in my code
Small Bug How to solve in my code  String season=""; pst = con.prepareStatement("SELECT DISTINCT(Season) season FROM specialdates where Regid...") + ","; it shows bug in findbugs tool.. but it executes successfully how to solve
help me about to solve my qustion
help me about to solve my qustion   An employee receives 15 SR per hour for the first 8 hours of week. After 8 hours (overtime) his rate becomes 20 SR per hour . Write a java class that ask a user to enter the number of hours he
please help me to solve this question about array
please help me to solve this question about array  write a program thatt stores vowels (a,e,i,o and u)in an array. Ask the user to enter any character. The program should ignore the case of that character (uppercase or lowercase
my question is related to my project viz
my question is related to my project viz   Sir, my project is based on MR tracking system developed using struts framework, it has been developed in Net Beans the whole project is working except a jsp page named dayplan.jsp
Solve it
Solve it  How to calculate the value which contains oparator and operand both using command line argument
solve this
solve this   Create a student class. The student object should have studentid, studentname, subject and marks as properties. Also generate the getter and setter methods. Create 5 objects of this class and populate values
Question
Question   When there is an exception in my program how java runtime system handles
question
question  dear sir/madam my question is how to compare two text format in java..we are java beginners..so we need the complete source code for above mentioned question...we have to compare each and every word
question
question  Dear sir i had some typing mistake at previous question so its my humble request to let me know the steps to start the tomcat6 under the tomcat directory
solve this pbm
solve this pbm  its not working the code for databae access using servlets
question
question  how to solve the problem of The requested resource is not available+java+eclipse
ModuleNotFoundError: No module named 'solve'
ModuleNotFoundError: No module named 'solve'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'solve' How to remove the ModuleNotFoundError: No module named 'solve'
question
/) is not available.** how tdo i solve this.please help me to run my project please give
question
question  how to solve the below problem com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'emp_id' in field list is ambiguous
how to solve
how to solve   log4j:WARN No appenders could be found for logger (org.apache.struts.util.PropertyMessageResources). log4j:WARN Please initialize the log4j system properly
question
question   sir plz tell me what should i give in title box. just i want java program for the question typed in this area
question
question   sir plz tell me what should i give in title box. just i want java program for the question typed in this area

Ads