asp.net中的正则表达式验证器 [英] Regular expression validator in asp.net

查看:91
本文介绍了asp.net中的正则表达式验证器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的网站上为文本框使用正则表达式验证器



文本框只能接受5到20之间的数字,必须是数字,否则任何字母和其他人



请帮我解决这个问题



谢谢

I want to use a regular expression validator for a textbox in my website

The textbox must only accept number ranging from 5-20 and must be number with no any letters and others

please help me out to sort this out

thanks

推荐答案

我建​​议进行以下验证,而不是使用正则表达式:

Instead of using Regular Expression, I would suggest the following validation:
  1. 将输入字符串的长度与5和20进行比较,检查它是否在有效范围内。 (您可能希望在执行之前修剪字符串。)
  2. 检查这是否是有效数字:

  1. Compare the length of the input string with 5 and 20, check up if it's in the valid range. (You may want to trim the string before doing it.)
  2. Check if this a valid number:
Dim input As String = ' ...
Dim value As ULong
If ULong.TryParse(input, value) Then
    ' input is valid, and value is a valid number
End If





为什么?因为您的一个验证步骤也会为您提供免费的数值;你很需要它。 :-)



-SA


在正则表达式下面检查,并检查它是否已解决

' \b1 [5-20] \b '
Checkout below regular expression, and check if it resolved
'\b1[5-20]\b'


这篇关于asp.net中的正则表达式验证器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆