drbouzlxb92333332 2016-04-16 05:33
浏览 17

如何验证多种模式?

I have a single form element that sends its value to a PHP script. This value needs to be validated and it there are 5 different sets that it can be grouped to,

x stands for digits 0-9

Set 1: ABxxTXxx

Set 2: ABxxTXAxxx

Set 3: ABCxxx

Set 4: Axxx

Set 5: xxx

Can this be done? Is there any library I could use?

  • 写回答

2条回答 默认 最新

  • duandi6531 2016-04-16 06:17
    关注

    Sorry for my above posting as i am still unable to add comment to a question.

    hi innowqhy,

    write 5 different regular expression matching 5 patterns that are given above function fieldsCheck(){

    var re1=/AB\d\dTX\d\d$/;
    var re2=/AB\d\dTXA\d\d$/;
    var re3=/ABC\d{3}$/;
    var re4=/A\d{3}$/;
    var re5=/\d{3}$/;
    var field= form.field.value;
    
    if(re1.test(field) ||re2.test(field) ||re3.test(field) ||re4.test(field) ||re5.test(field) ){
    alert("Test success");
    return true;
    }else{
    alert("test failed");
    }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题