?
Solved

Validate Phone Number Java

Posted on 2006-05-22
4
Medium Priority
?
1,007 Views
Last Modified: 2011-09-20
I have a form that has multiple phone number text fields.  I want the phone number formatted: xxx-xxx-xxxx as it is typed in.  I want the fields to have two options: 1) it can be blank  or 2) it can have xxx-xxx-xxx (in numbers of course).  If the full phone number is not entered and the field is not null, then upon the cursor going out of the textbox I want a popup to occur letting the person know it is not a valid phone number.

Any suggestions?
0
Comment
Question by:jeffreytp
  • 2
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
BogoJoker earned 500 total points
ID: 16738849
Hi jeffreytp,

Here is a good regex:
var regex = /^\d{3}-\d{3}-\d{4}$/;

Here is a working example:
<script type="text/javascript">
var regex = /^\d{3}-\d{3}-\d{4}$/;
</script>

Phone Number: <input type="text" onBlur="if (this.value == '' || regex.test(this.value)) {} else { alert('Phone number must be: xxx-xxx-xxxx'); this.focus(); }">

Joe P
0
 

Author Comment

by:jeffreytp
ID: 16744563
It works like a charm.  Thank you very much for the accurate quick response!
0
 
LVL 17

Expert Comment

by:BogoJoker
ID: 16744598
30 minutes is hardly quick =), most are answered within 5-10 minutes. =)
Joe P
0
 

Author Comment

by:jeffreytp
ID: 16744884
Why don't you give this one a crack then, I am still without an answer:

http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_21814605.html
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Suggested Courses

807 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