To do the testing against the regex, you can use the
test
method on
RegExp
.
RegExp.prototype.test() - JavaScript | MDN[
^]
if (re.test($('#<%=txt.ClientID%>').val()))
It's not at all easy to add the rule against consecutive chars in the regex which you already have. Therefore, I propose that you use a second regex: the first regex is to check that it only contains alphanumeric chars, slashes, hyphens and whitespace (you already have this regex), the second regex is to check if there are consecutive slashes and/or hyphens. This regex would look like this:
var re_consecutive_chars = /[/-]{2,}/;
If the textbox value matches this regex, you know that it has consecutive slashes, consecutive hyphens, a slash followed by a hyphen or a hyphen followed by a slash.
I'd also like to say this: I don't know whether you will use the textbox value on the server, but if you do, don't forget to do validation on the server as well. Client-side validation can easily be turned off by users. Server-side validation cannot.