Below is the code which can be used to validate alphabetic charecters using javascript regular expressions
//Alphanumeric validations
function validatealphanumeric(name)
{
var letters = /^[0-9a-zA-Z\s]+$/;
if(name.match(letters))
{
return true;
}
else
{
return false;
}
}
Usage:
var empnumber=trim(document.getElementById('name').value);
if(validatealphanumeric(empnumber))
{
//return true
}
else if((empnumber=="") || (empnumber=="0") || (empnumber=="null") || (empnumber=="NIL") || (empnumber=="nil"))
{
alert('Please enter valid Employee Number');
return false;
}
else
{
alert('Employee Number must have alphanumeric characters only');
return false;
}
//Alphanumeric validations
function validatealphanumeric(name)
{
var letters = /^[0-9a-zA-Z\s]+$/;
if(name.match(letters))
{
return true;
}
else
{
return false;
}
}
Usage:
var empnumber=trim(document.getElementById('name').value);
if(validatealphanumeric(empnumber))
{
//return true
}
else if((empnumber=="") || (empnumber=="0") || (empnumber=="null") || (empnumber=="NIL") || (empnumber=="nil"))
{
alert('Please enter valid Employee Number');
return false;
}
else
{
alert('Employee Number must have alphanumeric characters only');
return false;
}
No comments:
Post a Comment