Solved

Edit mask or picture validation

Posted on 1998-10-07
4
269 Views
Last Modified: 2008-03-04
I have two fields represent phone number.
The first has 3 digits for area code and the second has
8, 7 for the actual phone number and 1 for the dash.

I would like to put an edit mask on the 2nd field so that they enter the phone number like this 819 773-0738
Both fields are input text and I would like to perform this validation using the onChange event.
Does anyone have a good example of this?
0
Comment
Question by:adbdev2
  • 2
  • 2
4 Comments
 

Author Comment

by:adbdev2
ID: 1271876
Edited text of question
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1271877
0
 

Author Comment

by:adbdev2
ID: 1271878
that is a different scenario and too much for what I'm trying to do.  Already saw that page and would like a simpler example.  Thanks though.
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 20 total points
ID: 1271879
The idea was to get rid of what you didn't need...
But ok It is complex.

Try this - not eleant, but it is very simple:
<SCRIPT LANGUAGE="JavaScript">
function checkPhone(phoneNumber) {
   var Error = false;
   phoneNumber =+ ''; // force string
   if (!phoneNumber || phoneNumber.length != 12) Error = true;
   else {
      for (i=0;i<phoneNumber.length;i++)
          if (i=3 && phoneNumber.charAt(i) != ' ') {
             Error = true;
             break;
          }
          else if (i=7 && phoneNumber.charAt(i) != '-') {
             Error = true;
             break;
          }
          else if (!isDigit(phoneNumber.charAt(i)) {
             Error = true;
             break;
          }
      }
   }
   if (Error) {
      alert('The phonenumber ' + phoneNumber + ' needs to be in the format nnn nnn-nnnn);
      return false;
}
function isDigit(c) { return ((c >= "0") && (c <= "9")) }
</SCRIPT>

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question