dongzhi5587 2016-03-22 19:16
浏览 35
已采纳

正则表达式NIC [关闭]

Can you please help me in validation a mauritian NIC.

[1 capital letter][dateofBirth][6 numbers][1 capital letter]

Note: date of birth format: ddmmyy

I tried this one:

/^[A-Z]{1}[0-9]{12}[A-Z]{1}$/

But how do i validate the date of birth in the NIC? Thank you

  • 写回答

2条回答 默认 最新

  • dongxing8650 2016-03-22 19:22
    关注

    If you want to validate the date, you'll have a hard time doing so just with regex. But, fortunately, PHP has a checkdate function. You just have to extract the day, month and year, which should be pretty easy but will slightly change your regex. Don't forget to put parenthesis around each element (day, month, year), to be able to retrieve them.

    If I'm not mistaken, your regex should be something like that :

    /^[A-Z]([0-9]{2})([0-9]{2})([0-9]{4})[0-9]{6}[A-Z]$/
    

    Then check the date, so:

    preg_match('/^[A-Z]([0-9]{2})([0-9]{2})([0-9]{2})[0-9]{6}[A-Z]$/', 'D160289784495A', $match);
    
    var_dump(checkdate($match[2], $match[1], $match[3]));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据