
<html>
<head>
<script>
function checkphoneNumber(number){
if(/[^\d ]/.test(number)){
alert('It should contain numbers [0-9] only!');
document.getElementById("st").value="";
return false;
}
if(number.substring(0,2)!="2,5"){
alert("Number should begin with 2,5");
document.getElementById("st").value="";
return false;
}
if (number.length>10{
alert("Invalid phone Number!It cannot exceeds the limit of 10 digits. ");
document.getElementById("st").value="";
return false;
}
return true;
}
</script>
</head>
<body>
Enter phone Number:   <input type="text" id="st" onkeyup="checkMobileNumber(this.value);">
</body>
</html>
this is a phone number validation but it s not working correctly,,,,, it have accept alphabetic character,,,so plze send me right code

you have done mistakes at many places such as in the textbox event you are calling the wrong method name than the method you have made in script, and there are some more syntactical errors also. I have corrected your errors now you can run your code easily. I have also made changes in the calling of your method i.e. in place of textbox event I have called it on form event i.e. onsubmit event.
The changed code is as follows :
<html>
<head>
<script>
function checkphoneNumber(number){
//var num = number.value;
if(/[^\d ]/.test(number)){
alert('It should contain numbers [0-9] only!');
return false;
}
if(number.substring(0,2)!="2,5"){
alert("Number should begin with 2,5");
return false;
}
if(number.length > 10 || number.length < 10){
alert("Invalid phone Number! Number must contain 10 digits. ");
return false;
}
return true;
}
</script>
</head>
<body>
<form action="#" onsubmit="checkphoneNumber(document.getElementById('st').value)">
Enter phone Number: <input type="text" id="st">
<input type="submit" value="submit"/>
</form>
</body>
</html>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.