【问题标题】:pattern in angular 2 that not allow only spaces and any special characters, it should allow characters,numbers, underscore and hypen角度 2 中的模式,不仅允许空格和任何特殊字符,它应该允许字符、数字、下划线和连字符
【发布时间】:2017-03-25 17:02:25
【问题描述】:

我需要只允许字符、数字、下划线和连字符的验证器。如果用户仅输入空格,则禁用 angular 2 FormBuilder validators.pattern() 中的保存按钮。我已经试过了 Validators.pattern(".*\\S.*") and Validators.pattern(".*\\S.*[a-zA-z0-9 ]") 但没用。

【问题讨论】:

    标签: angular


    【解决方案1】:

    这样使用

    Validators.pattern(".*\\S.*[a-zA-z0-9_-]")
    

    Working Demo

    另见

    【讨论】:

    • 根据工作演示,如果我们输入特殊字符和字母的组合,则它无法正常工作。
    • 例如。如果像这样输入 abc%k 则它不起作用。
    • opps 我没有在你的问题中看到特殊符号,顺便说一句好问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多