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

<title>only alphabets</title>
<script language="javascript" >
function checkName()
re = /^[A-Za-z]+$/;
alert('Valid Name.');
alert('Invalid Name.');





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





lauragray 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

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

Anonymous said...

thanx for providing such a easy code....

Post a Comment

Blogger Themes

Powered by Blogger