zoukankan      html  css  js  c++  java
  • js 验证身份证号,根据身份证获取出生年月/性别

    // 校验身份证
    export const checkNumber = (number) => {
      const reg = /(^d{15}$)|(^d{18}$)|(^d{17}(d|X|x)$)/;
      return reg.test(number);
    };
    
    // 根据身份证,获取 出生年月日
    export const getBirthBySfzh = (sfzh) => {
      const year = sfzh.substr(6, 4); // 身份证年
      const month = sfzh.substr(10, 2); // 身份证月
      const date = sfzh.substr(12, 2); // 身份证日
      const birth = `${year}-${month}-${date}`;
      return birth;
    };
    // 根据身份证,获取 性别
    export const getSexBySfzh = (sfzh) => {
      const num = sfzh.substring(16, 17);
      return num % 2 === 0 ? '女' : '男';
    };


    // 校验手机电话格式
    export const checkPhone = (phone) => {
      const myreg = /^(1d{10})$/;
      return myreg.test(phone);
    };
    
    // 校验手机电话格式
    export const checkMobilePhone = (phone) => {
      const myreg = /^(d{7})$/;
      return myreg.test(phone);
    };
    
    export const isNumber = (number) => {
      const myreg = /^(d+)$/;
      return myreg.test(number);
    };
  • 相关阅读:
    基于centos的freeradius高可用lvs(UDP)
    sql server 2012的AlwaysOn高可用
    python基础题型一
    用户访一个APP或者网页流程示意图
    DNS解析流程
    crontab的定时任务实例
    Xcode设置
    Nvidia Nsight + .NET
    C++ Pointer-to-Member Selector
    C++11
  • 原文地址:https://www.cnblogs.com/arealy/p/14215054.html
Copyright © 2011-2022 走看看