June 12, 2009

6 Javascript allow only alphabets validation

this is a only alphabets javascript validation script for users who want to allow only alphabets in text box and no numbers in text box. good handy script for all users.try it out and give out your comments if you like this script
 

<html>
<head>
<title>only alphabets</title>
<script language="javascript" >
function checkName()
{
re = /^[A-Za-z]+$/;
if(re.test(document.insertDetails.uname.value))
{
alert('Valid Name.');
}
else
{
alert('Invalid Name.');

}

}
</script>

</head>

<body>

<form name="insertDetails" >
Enter your name: <input type="text" name="uname" />
<br>
<input type="button" value="Check" onClick="checkName()" />

</form>

<body>

</html>

6 comments:

laura said...

Thank you for posting this java script tips this is very informative. But i been looking forward the web programmer tips. I hope i can see that!

raj said...

heya laura raj, hr, thanks for ur comment,u want web programmer tips like what u want, u inform us, we will post the same, as due to some time constraints we are unable to post more

but user queries and suggestions are taken utmost care of, so we request you to plss send ur queries what u want in programmer topics, like, we post the same and let u know. do mention ur email id too

mozoella said...

thanks for posting the javascript validation script, its really going to be helpful because its easier than java for non-programmers to work with. It also saves the server from extra processing and detects visitors browser and enables programmatic access to objects within both the clients application or other application.
VPS Hosting

Prashant said...

what if want space?
your expression is not working for space.

raj said...

dude this code is designed for allowing alphabets no space no other characters...fr space code has to be modified..

giving u modified code...try out and let me know once

1.
/*
2.
For Letters: [a-zA-Z] (dealing with both upper and lower case characters)
3.
For Space: [ ]
4.
Putting them together: [a-zA-Z ]+
5.
Use a + instead of * since a blank string is not a valid letter nor a space.
6.
Use ^ and $ since our string should start and end with the given pattern.
7.
*/
8.
var myStr = "hello";
9.
if(/^[a-zA-Z ]+$/.test(myStr) {
10.
window.alert("String contains only alphabets and spaces");
11.
} else {
12.
window.alert("String doesn't contain only alphabets and spaces");
13.
}

Anonymous said...

thanx for providing such a easy code....

Post a Comment

Blogger Themes

 
Powered by Blogger