zoukankan      html  css  js  c++  java
  • js验证

    JS验证

    1.     只能是汉字

    <input onkeyup="value="/oblog/value.replace(/[^\u4E00-\u9FA5]/g,'')">

    2.     长度限制

    function test() {

                if (document.a.b.value.length > 50) {

                    alert("不能超过50个字符!");

                    document.a.b.focus(); return false;

                }

            }

    3." 只能是英文

     

            function onlyEng() {

                if (!(event.keyCode >= 65 && event.keyCode <= 90))

                {

                    event.returnvalue = false;

                }

            }

    4.只能是数字

    function onlyNum() {

                if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)))

                {

                    event.returnvalue = false;

                }

            } //考虑小键盘上的数字键 even

    5.只能是英文字符和数字

    <inputonkeyup="value="/oblog/value.replace(/[\W]/g,"'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">

    6屏蔽关键字

    function test() {

                if ((a.b.value.indexOf("***") == 0) || (a.b.value.indexOf("****") == 0)) {

                    alert(":)"); a.b.focus(); return false;

                }

            }

    7屏蔽鼠标右键

    屏蔽右键 很酷 oncontextmenu="return false" ondragstart="return false" onselectstart="return false" 加在body中

    8.只能为数字下划线(可自定义)

    function isNumber(String) {

                var Letters = "1234567890-"; //可以自己增加可输入值

                var i; var c;

                if (String.charAt(0) == '-') {

                    return false;

                }

                if (String.charAt(String.length - 1) == '-') {

                    return false;

                }

                for (i = 0; i < String.length; i++) {

                    c = String.charAt(i);

                    if (Letters.indexOf(c) < 0) {

                        return false;

                    }

                } return true;

            }

    9.是否含有汉字

     

            if (escape(str).indexOf("%u") != -1)

            { alert("含有汉字"); } else

            { alert("全是字符"); }

  • 相关阅读:
    [CF845G]Shortest Path Problem?
    [洛谷P4149][IOI2011]Race
    [洛谷P4178]Tree
    [AtCoder AGC27A]Candy Distribution Again
    [洛谷P3806]【模板】点分治1
    [洛谷P2634][国家集训队]聪聪可可
    [CF280C]Game on Tree
    [洛谷P3338][ZJOI2014]力
    [CF438D]The Child and Sequence
    [CF609E]Minimum spanning tree for each edge
  • 原文地址:https://www.cnblogs.com/dongwenhua/p/8989220.html
Copyright © 2011-2022 走看看