How do I use a submit function to ensure that a name field only has letters, zip code field only has numbers, etc. w/ Javascript when submitting a form?
kahaj
0
Junior Poster
Recommended Answers
Jump to Postuse the concept at this url
http://www.w3schools.com/js/js_form_validation.asp
in conjunction with this url
http://developer.apple.com/internet/webcontent/validation.html
Jump to Postthis is for checking only numbers:
function Only_Num(id) { if(isNaN(document.getElementById(id).value)) { alert("Please Enter Only Numbers (0-9).."); document.getElementById(id).value=""; document.getElementById(id).focus(); } return; }
this for only letters:
function isAlphabet(elem, helperMsg){ var alphaExp = /^[a-zA-Z]+$/; if(elem.value.match(alphaExp)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } }
Jump to PostCheck this url:
http://www.tizag.com/javascriptT/javascriptform.phphere you can find all types of validations with working examples...
All 11 Replies
R0bb0b
344
Posting Shark
kahaj
0
Junior Poster
kahaj
0
Junior Poster
kahaj
0
Junior Poster
TnWbDzgnr1996
0
Newbie Poster
kahaj
0
Junior Poster
Shanti C
106
Posting Virtuoso
Shanti C
106
Posting Virtuoso
~s.o.s~
2,560
Failure as a human
Team Colleague
Featured Poster
krishikrishi1
0
Newbie Poster
TnWbDzgnr1996
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.