validating for string using regular expression

Posted: April 3, 2010 in JavaScript Stuffs
Tags: ,

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;
}
}

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s