zoukankan      html  css  js  c++  java
  • JS判断数字字母中文

    1.

    var reg = /^(\w|[\u4E00-\u9FA5])*$/;
    if(arr=username.match(reg))
     {
     ti=1;
     return ture;
    }
    else
    {
     alert("用户名只允许为英文,数字和汉字的混合,\n请检查是否前后有空格或者其他符号");
     ti=0;
     return false;
    }

    2.利用正则表达式限制网页表单里的文本框输入内容:

    用正则表达式限制只能输入中文:onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))"

    用正则表达式限制只能输入全角字符: onkeyup="value=value.replace(/[^\uFF00-\uFFFF]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\uFF00-\uFFFF]/g,''))"

    用正则表达式限制只能输入数字:onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"

    用正则表达式限制只能输入数字和英文:onkeyup="value=value.replace(/[\W]/g,'')

  • 相关阅读:
    使用dfs求解全排列
    并查集
    Best Cow Line
    Saruman's Army
    Fence Repair
    Laking Counting
    淘宝商品定向爬取
    爬取股票信息
    python中的正则表达式的使用

  • 原文地址:https://www.cnblogs.com/happyday56/p/976421.html
Copyright © 2011-2022 走看看