Solved

Edit mask or picture validation

Posted on 1998-10-07
4
271 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

679 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