Codepedia
.info
Home
About
Demos
Tools
SVG Wave Generator
Colors
Edit This Code :
<html> <body> <input onkeypress="return Validate(event);" type="text" /><br/> <span style="color:red;" id="lblErrorMsg"></span> <script> function Validate(e) { var keyCode = e.keyCode || e.which; var errorMsg = document.getElementById("lblErrorMsg"); errorMsg.innerHTML = ""; //Regex to allow only Alphabets Numbers Dash Underscore and Space var pattern = /^[a-z\d\-_\s]+$/i; //Validating the textBox value against our regex pattern. var isValid = pattern.test(String.fromCharCode(keyCode)); if (!isValid) { errorMsg.innerHTML = "Invalid Attempt, only alphanumeric, dash , underscore and space are allowed."; } return isValid; } </script> </body> </html>
➤ Run / View
Result :