Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript Name field validation!

Status
Not open for further replies.

micjohnson

Programmer
Nov 9, 2000
86
US
I need to validate my Name field. Field should be only characters. No numbers in that. Any script available to validate (First name or Last Name)

Appreciate

micJ
 
a) give it a maxlength
b) use a regex.

Code:
function validateCharsOnly(obj) {
    var re = /^[a-zA-Z]+$/;
    alert( re.text(obj.value) );
}

Code:
<input type="text" name="t1" onblur="validateCharsOnly(this);" />

ideally you'd want to call something like this when submitting a form. however, the example above calls when you leave the field. the test is for letters only.

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
beware of active imagination: [URL unfurl="true"]http://www.coryarthus.com/[/url]

BillyRayPreachersSonIsTheLeetestHax0rDude
[banghead]
 
I tried but i got an error as "Object does not support this property or method"

I am trying to fix this error.

Regards

micJ
 
i've been really bad today.

in my code above, .text should be .test.

sorry about that.

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
beware of active imagination: [URL unfurl="true"]http://www.coryarthus.com/[/url]

BillyRayPreachersSonIsTheLeetestHax0rDude
[banghead]
 
Thanks lot for your reply. Working good now.

Regards
micJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top