jump to navigation

Numeric input only for a HtmlInputField January 12, 2006

Posted by codinglifestyle in ASP.NET, Javascript.
Tags: , ,
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,\”\”);”);

Advertisements

Comments»

1. Ab - September 14, 2006

Thanks!

That just came in really handy.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: