Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Edit mask or picture validation

Posted on 1998-10-07
4
Medium Priority
?
275 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 80 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

604 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