Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JavaScriptQuestions solve my question shortly
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


priya kumari
solve my question shortly
1 Answer(s)      a year and 10 months ago
Posted in : JavaScript Questions


<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


Advertisement
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>


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
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
Advertisements
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...  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
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
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
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
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
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
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
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
my question - EJB
my question  is it possiable to create web application using java beans & EJB's with out implementing Servlets and jsps in that java beans and EJB's
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
need to solve the below question - Java Beginners
need to solve the below question  I need to write an application that uses the circle class.it must read a radius of a circle from the user .create a circle object and return the object
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
clarify my question - Java Beginners
clarify my question  Dear Sirs/Expert, Thanks for writing back. Yes. I want a page to use id of parents to do the search for the match. So... the matching tutors to the parent. I was telling you that my degree
Regarding My 3rd Question in Java - Swing AWT
Regarding My 3rd Question in Java  sir in Netbeans By default JTable Columns will appear Horizontal like Title1 Title2 Title3 Title4 in below these our data will appear so my question that is there any method
Clarify my last question's answer - Java Beginners
Clarify my last question's answer  Dear expert, I've tried out... did not specify my question too clearly. Here's my 2 database... and parents contain other fields like name, address, email, contact numbers etc. My
Some additions for my previous question - Java Beginners
Some additions for my previous question  This is the question I... for the GUI. Could anyone please help?" So my other two questions are: 1... the user with a command line menu. The choices are p, f, q and n. In case
Further advice needed on my last question - JSP-Servlet
Further advice needed on my last question  Dear Experts, I refer to your last solution regarding my matching codes. After I tried out your... errors Here are my codes which I modified but basically followed your logic
solve this pbm
solve this pbm  its not working the code for databae access using servlets
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
solve this pbm
solve this pbm  sir rows are also inserting i have checked in the database also the rows are not affected in the table . The first pbm wich i have sent to you is not yet solved.......... pls give me detail explaination how we
Advertisements
 

 

 

DMCA.com