Hi,
I'm New to java Script ,i need to validate some text field,email field,number filed ,give me some advice to do that,any links to refer any ebooks.
Thanks in advance
Malick
Hi,
I'm New to java Script ,i need to validate some text field,email field,number filed ,give me some advice to do that,any links to refer any ebooks.
Thanks in advance
Malick
Javascript is not the tool for the job in this case. Validation must be performed server-side (although you may wish to do it on the client as well, for convenience).
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
I do agree with Twey, but as per request, you can validate a textbox's value if it's a valid email by RegEx:
HTML Code:<script type="text/javascript"> var ray={ checkEmail:function(el) { alert(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(this.returnVal(el))?'Congratulations! It\'s a valid email address':'Sorry, it\'s an invalid email address'); }, checkNum:function(el) { // For regex, you can use \d - to test it value is decimal alert(!isNaN(Number(this.returnVal(el)))?'It\'s a valid number':'It\'s an invalid number'); }, returnVal:function(el) { return document.getElementById(el).value; } } </script> <label for="email">Email Address: </label> <input type="text" id="email"><br> <label for="number">Number: </label> <input type="text" id="number"><br> <input type="button" value="Validate Email" onclick="ray.checkEmail('email')"> <input type="button" value="Validate Number" onclick="ray.checkNum('number')">
Learn how to code at 02geek
The more you learn, the more you'll realize there's much more to learn
Ray.ph!
Bookmarks