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
escaping
/
like\/
is a good practise but inside of char class, not necessary.
the*
must be changed to+
. because*
will also matchnull
.
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');
}
}