【问题标题】:asp:RegularExpressionValidator Minimum 8 characters and 1 Special Characterasp:RegularExpressionValidator 最少 8 个字符和 1 个特殊字符
【发布时间】:2017-01-23 21:12:47
【问题描述】:

我试过几个,我有 ValidationExpression="^(?=.*[A-Za-z])(?=.*?[#?!@$%^&*-=+])[A-Za-z\d$@$!%*#?&]{8,}$" > 但是,我需要它来允许所有特殊字符(^、=、+ 等)

谢谢

【问题讨论】:

    标签: c# asp.net regex


    【解决方案1】:
    "^(?=.*?[#?!@$%^=+*&-]).{8,}$"
    

    您可以使用“\”转义字符“-”。或者只需确保“-”是特殊字符列表中的最后一个字符,否则它将在“-”周围的字符之间选择一个范围。在您的情况下'*-='.测试表达式here

    (?=.*?[#?!@$%^*&=+-]) Alteast [] 中的 1 个特殊字符。在最小集中添加更多您想要的字符,如果需要,使用“\”转义。

    .{8,}$ 最少 8 个字符

    匹配

    ^testtes
    test%tes
    testtes+
    #?!@&tes
    1234567*
    testesttesttest1234567&
    TEST123!
    $TESTTES
    $0123121
    

    无匹配

    testtest
    testtes1
    12345678
    testesttesttest12345678
    test!
    t1@
    TEST1234
    $012312
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-18
      • 1970-01-01
      • 2019-12-07
      • 1970-01-01
      相关资源
      最近更新 更多