How can I check, if anyone entered a special character, in the signup form?
|
demo 20 Dec 2008 05:59am I dont want users to enter special letters as their usernames, in the signup form. how can I check it in ASP? (or javascript) only accepted letters must be A to Z, a to z and numbers only. if someone enter a letter which is not in english alphabet it must raise an error. i have enough knowledge about asp or javascript. i will be happy if you write the function only. i understand it. thanks. |
Answers
|
demo 20 Dec 2008 07:27am I wrapped the solution in "just enough" HTML for a demo. <head> <style> </style> <script type="text/javascript"> function validate( bRef ) { // get field to be validated var fld = document.getElementById( 'field0' ).value; // use regular expression pattern matching to detect // any characters NOT in the composite character set, // consisting of upper and lower case alphabetics and // numeric digits var invalid = fld.match( /[^A-Z,a-z,0-9]/g ); // if no matches, then all were valid, and content // of {invalid} is {null} (NOTE: ^ negates the set) if (null == invalid) { // do whatever you want for valid input, e.g., // var f = document.getElementById( 'myForm' ); // OR var f = bRef.parentNode; // f.submit(); } else { // do whatever you want for invalid input, e.g., alert('form contains invalid characters:n' + invalid); } } </script> </head> <body> For demo purposes... <form id="myForm"> <input type="text" id="field0" /> <input type="button" value="submit" onclick="validate( this )" /> </form> </body> </html> |
Related
Submit Answer
You must be logged in to post an answer. Please Login or Register.
Powered by phpMyAnswers.