How to restrict Html5 input to enter single quote and colon
forms, html, jsp, validation
Solution
I modified your HTML code with the validation using HTML5 regular expression
<form action="" method="post">
<input name="demo" type="text" id="demo" pattern="[^':]*$" />
<input type="submit" value="submit"/>
</form>
See fiddle here: http://jsfiddle.net/mzDt9/
Problem
I have created 1 jsp page that contain html form, while submitting html form i have checked input string for not contain any single quote(') or colon(:) ``` <form action="" method="post" onsubmit="return toValidate('demo')> <input name="demo" id="demo" /> <input type="submit" value="submit"/> </form> ``` Javascript function: ``` function toValidate(id){ var str = ""; for(var i=0; i<val.length;i++) { if (val[i] == "'" || val[i] == ":") { alert(" ' and : not allowed"); return false; } else { str =str+val[i]; document.getElementById(id).value=str; } } } ``` My question is that how can i restrict input field using html5 pattern...?