javascript and php validation script for phone number


The following validation are used for check your phone numbers are valid or not using regular expression……….

PHP

Using ereg function we can check phone number. Current phone number format is 000-000-0000

<?php

if(ereg(“^[0-9]{3}-[0-9]{3}-[0-9]{4}$”, $Phone){

echo “your phone number is valid”;

}  else{

echo “please check your phone number”;

}

?>

JAVASCRIPT

Using text function of javascript we can check regular expression of passing parameter. Current phone number format is 000-000-0000.

<script type=”text/javascript”>

function checkNumber(){

var regExp = /^[0-9]{3}[\- ]?[0-9]{3}[\- ]?[0-9]{4}$/;
if(!regExp.test(obj.value)){
alert(“enter valid phone numbers.”);
obj.value = ”;
obj.focus();
}

}

</script>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s