zoukankan      html  css  js  c++  java
  • 以正则表达式的方式校验身份证号码是否正确 和其他验证

    isIDCard1=/^[1-9]d{7}((0d)|(1[0-2]))(([0|1|2]d)|3[0-1])d{3}$|^[1-9]d{5}[1-9]d{3}((0d)|(1[0-2]))(([0|1|2]d)|3[0-1])d{3}([0-9]|X)$/; 

    正则表达式限制输入框只能输入数字      代码如下: 

    <input type="text" onkeyup="this.value=this.value.replace(/[^d]/g,'') " onafterpaste="this.value=this.value.replace(/[^d]/g,'') " name="f_order" value="1"/> 

    其中,onafterpaste防止用户从其它地方copy内容粘贴到输入框 



    输入框只能输入字母和下横线的正则表达式 
    <input onkeyup="this.value=this.value.replace(/[^_a-zA-Z]/g,'')" onpaste="this.value=this.value.replace(/[^_a-zA-Z]/g,'')"> 


    输入框只能输入字母数字和下横线的正则表达式 
    <input onkeyup="this.value=this.value.replace(/[^w]/g,'')" onpaste="this.value=this.value.replace(/[^w]/g,'')"> 
    或 
    <input onkeyup="this.value=this.value.replace(/[W]/g,'')" onpaste="this.value=this.value.replace(/[W]/g,'')">

    只能输入数字和英文的: 
    <input onkeyup="value=value.replace(/[W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))"> 
    2.只能输入数字的: 
    <input onkeyup="value=value.replace(/[^d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))"> 
    3.只能输入全角的: 
    <input onkeyup="value=value.replace(/[^uFF00-uFFFF]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^uFF00-uFFFF]/g,''))"> 
    4.只能输入汉字的: 
    <input onkeyup="value=value.replace(/[^u4E00-u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^u4E00-u9FA5]/g,''))"> 


    5.也可以这样: 输入数字和.,否则弹出输入有误 
    <input type=text name= caolig value ="" onblur="if (!(/^[d]+.?d*$/.test(this.value)) ){alert('您的输入有误'); this.value='';this.focus();}">

  • 相关阅读:
    [Leetcode Week17]Copy List with Random Pointer
    [Leetcode Week16]Range Sum Query
    [Leetcode Week16]Insertion Sort List
    [Leetcode Week15]Populating Next Right Pointers in Each Node II
    [Leetcode Week15]Populating Next Right Pointers in Each Node
    [Leetcode Week15] Add Two Numbers
    [Leetcode Week14]Path Sum II
    [Leetcode Week14]Construct Binary Tree from Inorder and Postorder Traversal
    [Leetcode Week14]Maximum Binary Tree
    [Leetcode Week13]Search a 2D Matrix
  • 原文地址:https://www.cnblogs.com/lst619247/p/8572005.html
Copyright © 2011-2022 走看看