View RSS Feed

Angad Kumar Shukla's blog

Name Validation Using Javascript

Rating: 10 votes, 4.60 average.
		<script type="text/javascript">
			function validateName(){
				var name=frm1.n1.value;
				var flag=true;
				for(var indx=0;indx<name.length;indx++)
						if(name.charAt(indx)!=' '){
							alert("Name is not valid..");
				return flag;
		<form name="frm1" onsubmit="return validateName()">
			Name<input type="text" name="n1"><br>
			Gender: Male<input type="checkbox" name="r1" value="Male">
			Female<input type="checkbox" name="r1" value="Female">
			<input type="submit" name="submit" value="Go">

Submit "Name Validation Using Javascript" to Digg Submit "Name Validation Using Javascript" to del.icio.us Submit "Name Validation Using Javascript" to StumbleUpon Submit "Name Validation Using Javascript" to Google

Java , Web Design


  1. Unregistered's Avatar
    This is fine for a standard last name like Smith, but what about a name like O'Connell for example?

    And why go through the trouble of look at each individual character? Why not just use regex?

Disclaimer: Users of techforum4u.com are responsible for ensuring that any material they post (article, blog posts, images or other mulitimedia content) does not violate or infringe upon the copyright, patent, trademark, or any personal or proprietary rights of any third party, and is posted with the permission of the owner of such rights.Anyone who violates these rules may have their access privileges removed without warning.