Javascript 无电子邮件和号码(最多允许5位数字)的正则表达式,可以添加字符串

Javascript 无电子邮件和号码(最多允许5位数字)的正则表达式,可以添加字符串,javascript,angularjs,Javascript,Angularjs,我希望应用验证,用户可以写入字符串,但不能以连续模式输入电子邮件id和编号,最多只能输入5位数字。 我正在尝试以下不起作用的内容: ^[a-zA-Z][0-9]{0,5}$ 如用户写入: 您好12345很好-->是的 你好134566坏了-->错了 hello+32444不正确-->错误 你好13233是好的,我有12333--->真的 提前感谢这应该对您有用: ^[A-z ,]*(([0-9]\s?){1,5})([A-z ,]*)(([A-z ,]+)(([0-9]\s?){1,5}))*

我希望应用验证,用户可以写入字符串,但不能以连续模式输入电子邮件id和编号,最多只能输入5位数字。 我正在尝试以下不起作用的内容:

^[a-zA-Z][0-9]{0,5}$
如用户写入:

  • 您好12345很好-->是的
  • 你好134566坏了-->错了
  • hello+32444不正确-->错误
  • 你好13233是好的,我有12333--->真的

  • 提前感谢

    这应该对您有用:

    ^[A-z ,]*(([0-9]\s?){1,5})([A-z ,]*)(([A-z ,]+)(([0-9]\s?){1,5}))*$
    
    说明:

    • ^
      匹配字符串的开头
    • [A-z,]*
      与数字前的文本匹配
    • (([0-9]\s?{1,5})
      将数字与其中的空格匹配
    • ([A-z,]*)
      匹配第一个数字后的文本
    • ([A-z,]+)([0-9]\s?{1,5})
      匹配所有其他带有空格的数字,如果数字之间有文本,则匹配ony
    • $
      匹配字符串的结尾

    我使用以下正则表达式作为解决方案:

    ^([a-zA-Z,\s]+[0-9\s]{0,5})+$
    
    有时人们输入带有空格的号码,特别是电话号码,以限制他们,我使用
    Keyup
    事件上的功能:

    valid(){
        this.commmentValid=false; //condition to show or not on html page
        var count=0;
        // Remove space from starting and end of string
        var a = (this.commentData.comment).trim(); 
        // Split each string value and form an array
        var m = a.split("");
        var preVal;
        // console.log(m)
        m.forEach(el => {
          console.log(el);
          var d= el.match(/\d+/);
          //Check if value is digit
          if(d){
            //Store previous value
            preVal=el;
            count++;
            if(count>=6){
              // Run when find phone number with and without space
              this.commmentValid=true;
            } 
          } 
          //If find space
          else if(el == " "){
            if(preVal){
              count++;
            }
          }
          //Check if string is ok
          else{
            count =0;
            preVal=0;
          }
        });
      }
    

    你能举几个例子吗?(对于匹配和不匹配)例如:hello 12345是好的-->True hello 134566是坏的-->false hello+32444是坏的-->false hello 13233是好的,我有12333-->True我有问题中的编辑案例你可以检查这个正则表达式而不是正则表达式匹配
    12345 6789
    ,你想要吗?