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 Post— R0bb0b 344use the concept at this url
in conjunction with this url
Jump to Post— Shanti C 106this 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 Post— Shanti C 106Check 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.