Numeric input only for a HtmlInputField January 12, 2006
Posted by codinglifestyle in ASP.NET, Javascript.Tags: Javascript, regular expression, validator
trackback
Sometimes a validator control is overkill, especially when you are dynamically creating all your web controls and just want a simple restriction. Below is a little javascript to require numeric input only:
HtmlInputField myField = new HtmlInputField();
myField.Attributes.Add(“onkeyup”, “this.value=this.value.replace(/[^\\d]*/gi,\”\”);”);
Thanks!
That just came in really handy.