美文网首页
常用的正则

常用的正则

作者: 三石青韦 | 来源:发表于2020-03-27 22:44 被阅读0次

    校验类

    操作类

    • 字符串前后去空:
      ' 11 1 '.replace(/(^\s*)|(\s*$)/g, ""); 结果: '11 1'

    • 输入大小写字母、数字、下划线:
      this.value.replace(/[^\w_]/g,'');

    输入小写字母、数字、下划线:
    this.value.replace(/[^a-z0-9_]/g,'');

    输入数字和点
    this.value.replace(/[^\d.]/g,'');

    输入中文:
    this.value.replace(/[^\u4e00-\u9fa5]/g,'');

    输入数字:
    this.value.replace(/\D/g,'');

    输入英文:
    this.value.replace(/[^a-zA-Z]/g,'');

    输入中文、数字、英文:
    value.replace(/[^\w\u4E00-\u9FA5]/g, '');

    输入数字和字母
    value.replace(/[\W]/g,'')

    相关文章

      网友评论

          本文标题:常用的正则

          本文链接:https://www.haomeiwen.com/subject/zxgruhtx.html