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

Recommended Answers

All 3 Replies

Can you post what was the solution?

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;
			}
		}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.