Solved

Edit mask or picture validation

Posted on 1998-10-07
4
273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article discusses how to create an extensible mechanism for linked drop downs.
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…

724 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