0

hello...

i am getting problem with this regex....what is the exact format of this pattern only 000-000-0000. exact this pattern only not other U.S phone number format. why because i am using below javascript for this validation.

if(window.document.UserDetails.phone.value=="")
{
alert("Please Enter The Phone Number")
window.document.UserDetails.phone.focus();
return false;
}

var pattern = /^\(?\d{3}[\)-\.]?\d{3}[-\.]?\d{4}$/;

if(window.document.UserDetails.phone.value!= "")
		{	
		 	var eres=window.document.UserDetails.phone.value.search(pattern);
			if(eres == -1)
			{
				alert("Enter Valid Phoneno i.e 000-000-0000 format");
				window.document.UserDetails.phone.focus();
				return false;
			}
		}

in this this number also validating correctly.
ex: 1234567890
123-4567890
(123)4567890.
these all are validating. but i want regex for only 000-000-0000 this format. how to change format please help me

2
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by muralikalpana
0
var pattern = /^\d\d\d\-\d\d\d-\d\d\d\d$/;
if(window.document.formx.phone.value!= "")
		{	
		
		 	var eres=window.document.formx.phone.value.search(pattern);
			if(eres == -1)
			{
				alert("Enter Valid Phoneno i.e 000-000-0000 format");
				window.document.formx.phone.focus();
				return false;
			}
		}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.