开发者

Textbox that accepts all the characters but returns only numbers

I need the code to filter the data entered in a textbox. Although it accepts all the characters during runtime, the code should remove all the strings and alpha numeric characters except the numbers (which would be my output). I tried the following code but 开发者_开发技巧guess it won't do:

a = Textbox1.text
Dim value As Decimal = CDec(Regex.Replace(a, "[\D]", ""))


Your regex was correct (just a bit redundant, \D would have done). Better would have been \D+ so consecutive non-decimals are replaced at once.

ResultString = Regex.Replace(SubjectString, "\D+", "")


I use this jQuery plugin. http://plugins.jquery.com/project/jQueryNumberLettersPlugin

$("#id").numbers();

That would only allow numbers to be entered into the selected input.


Try this instead, use the matching object

Dim a As String
Try
    a = Regex.Match(Textbox1.text, "\d+").Value     
Catch ex As ArgumentException
    'Syntax error in the regular expression
End Try
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜