Posts Tagged ‘validating for string using regular expression’

function check()
{
if (cutSpaces(myform.deptname.value)==”)
{
alert (“Department name can’t be blank “);
myform.deptname.focus();
return false;
}

if (cutSpaces(myform.hod.value)==0)
{
alert (“HOD name can’t be blank “);
myform.deptname.focus();
return false;
}

isAlphabet(document.getElementById(‘deptname’), ‘Letters Only Please’);
}

function isAlphabet(elem, helperMsg)
{
alert(elem.value);
var alphaExp = /^[a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}
else{
alert(helperMsg);
elem.focus();
return false;
}
}