<input type="text" id="NotesReturn" />
<script type="text/javascript">
$("#NotesReturn").keypress(function (e) {
kCode = e.keyCode || e.charCode
var htmlRegExp=new RegExp("/<(\w+)((?:\s+\w+(?:\s*=\s*(??:'[^']*')|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/");
if (htmlRegExp.test(kCode) || $(this).val().length >= 512)
e.preventDefault();
});
$("#NotesReturn").bind('paste', function(e){
var pastedValue=this.value+window.clipboardData.getData('Text');
var trimmedValue=pastedValue.substring(0, 512);
var htmlRegExp = new RegExp("/<(\w+)((?:\s+\w+(?:\s*=\s*(??:'[^']*')|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/");
if(!htmlRegExp.test(trimmedValue))
{
$(this).val(null);
$(this).val(trimmedValue.toString());
}
e.preventDefault();
});
</script>
My textbox should not allow html data.But it is throwing unexpected quantifier error.can someone help me.I could not figure out the error.
/at the beginning and end when you usenew RegExp(), you only do that when writing the regex as a literal.