js Validation forms JS

Posted by Johngoadby under JavaScript on 6/20/2013 | Points: 10 | Views : 943 | Status : [Member] | Replies : 1
Hi

Im having problems configuring this bit of code to allow numbers only PLEASE can you help


_____________________________

if(form.phone.value == '') {

alert('Please enter your telephone number');
form.phone.focus();
return false;
}

_____________________________


I managed to sort this one for simple email.

_____________________________

var emailID = form.email.value;
atpos = emailID.indexOf("@");
dotpos = emailID.lastIndexOf(".");
if (atpos < 1 || ( dotpos - atpos < 2 ))
{
alert("Please enter correct email ID")
form.email.focus() ;
return false;
}
_____________________________

Any help is most welcome




Responses

Posted by: Shameer.Ali87 on: 6/21/2013 [Member] Starter | Points: 25

Up
0
Down
hi, try this..

function check_MobileNo()

{
if(document.getElementById("TxtMobileNo").value=="")
{
alert("Please enter your Mobile No !!!");
document.getElementById("TxtMobileNo").focus();
return false;
}
var x = document.getElementById("TxtMobileNo").value;
if(isNaN(x)||x.indexOf(" ")!=-1)
{
alert("Mobile No Should Contain Only Numbers!!!");
document.getElementById("TxtMobileNo").focus();
return false;
}
var a=document.getElementById("TxtMobileNo").value;
if((a.length<10)||(a.length>10)) // here mobile no should contain only 10 numbers
{
alert("Mobile No Should be atleast 10 Characters..");
document.getElementById("TxtMobileNo").focus();
return false;
}
return true;
}


thanks,

shameer ali shaik

Johngoadby, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response