Solved

Edit mask or picture validation

Posted on 1998-10-07
4
261 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
Comment Utility
Edited text of question
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
0
 

Author Comment

by:adbdev2
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now