Hi all I have the following Regx that can’t be accepted on the JavaScript
if ($(caller).attr('value').toString().search('/(?=\D*\d\D*\d).{8,15}/g') == -1)
where
$(caller).attr('value').toString() = "fdsddfsd45"
it returns to me -1
also I’m try to test it from pattern
if (!pattern.test($(caller).attr('value'))) {
where
pattern = /^(?=D*dD*d).{8,15}$/
it returns to me false
$(caller).attr('value').toString() = "fdsddfsd45"
when I tried to test it through desktop application called RegExr this string “fdsddfsd45” match the expression (?=\D*\d\D*\d).{8,15} is this JavaScript bug I don’t know ?
In JavaScript the regex should either be a string or a regex literal. In your case, this should do it:
Note that I removed the single quotes. I’ve also remove the
/gflag – since you are searching for any match, you don’t need it.For completeness, while it less useful, you could have written the regex as a string, but you’d have to escape all backslashes, or JavaScript will parse
\dasdbefore it even reaches the regex. In this case, you don’t need the slashes (unlike PHP, for example, which uses both):Example: http://jsbin.com/ubuce3