Reputation: 151
please help I have the regex line ^((?![<>=^@#]).)*$
which checking not ordinary symbols in an input field, it's ok but I need to add for this line one more condition , my line need to have vs.
For example when we have the name of sport game like this Patriots vs. Tigers
How can I complete my ^((?![<>=^@#]).)*$
condition and add rule for checking vs. in line (input field must have vs.) ?
It will be so cool if conditional also check spaces around vs. at left and at right, because for example Patriotsvs.Tigers is not good and need to show error also
Upvotes: 0
Views: 60
Reputation: 1374
You can use look aheads with the start anchor to effectively use multiple conditions. Here is something that should work for you:
^(?=((?![<>=^@#]).)*$)(?=.*?\svs\.\s).*$
Will match:
thing vs. another
Patriots vs. Tigers
Won't match:
th%^hg vs. another
thing another
thingvs.another
Upvotes: 0
Reputation: 120496
I think what you want is
/^[^<>=^@#]*?\bvs\.[^<>=^@#]*$/
which blacklists the characters [<>=^@#]
and requires the literal text "vs.
" somewhere in the string.
That character blacklist is probably insufficient if you're trying to only approve inputs that won't lead to SQL-injection or XSS. Please consider using a stock input filtering/escaping system with this.
Upvotes: 1