REGEX - must contain alphanumeric and slash

后端 未结 3 970
执笔经年
执笔经年 2021-01-27 03:27

I am trying to do a validation that an input field must contain alpha numeric and slash as its value.

Eg: AA/AB/12314/2017/ASD

The above shown is the example of

3条回答
  •  有刺的猬
    2021-01-27 04:05

    escaping / like \/is a good practise but inside of char class, not necessary.
    the * must be changed to +. because * will also match null.
    also remove the - otherwise - will also be matched.

    function validate(){
      var message = $('#message').val();
    
      if (/^[a-zA-Z0-9/]+$/.test($.trim(message)) == false){
          $('#message').focus();
         alert('invalid message');
      }
    }
    
    

提交回复
热议问题