Code Snippets

  

JavaScript Source Code


Welcome to Dream.In.Code
Become an Expert!

Join 148,867 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,213 people online right now. Registration is fast and FREE... Join Now!





Validate Phone Number

Validates a phone number against the regular expression: (555) 555-1234

Submitted By: skyhawk133
Actions:
Rating:
Views: 38,488

Language: JavaScript

Last Modified: February 28, 2005
Instructions: Call using isPhoneNumber(form.field.value);

Returns Boolean

Snippet


  1. function isPhoneNumber(s)
  2. {
  3.  
  4.      // Check for correct phone number
  5.      rePhoneNumber = new RegExp(/^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/);
  6.  
  7.      if (!rePhoneNumber.test(s)) {
  8.           alert("Phone Number Must Be Entered As: (555) 555-1234");
  9.           return false;
  10.      }
  11.  
  12. return true;
  13. }

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.




Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month