Hi,
This didn’t seem to work:
if (vLocation_student == /^d{10}$/) { …
…where I’m looking for 10-digit numeric content like “0123456789”, which can have one or more leading zeroes.
Where am I going wrong?
Thanks so much,
Don
Hi,
This didn’t seem to work:
if (vLocation_student == /^d{10}$/) { …
…where I’m looking for 10-digit numeric content like “0123456789”, which can have one or more leading zeroes.
Where am I going wrong?
Thanks so much,
Don
Oops, nevermind…didn’t realize that I needed to use .match() !!
Don (newbie )
You can also use .test():
if (/\^d{10}$/.test(vLocation_student)) {
Thank you Joas.
Is it also possible to do the following? I ran into some trouble with the global method, when doing the .match() on a large string for US date validation.
var csisTest = ‘/^d{10}$/’ // placed in global method
if (globals.csisTest.test(vLocation_student)) { …
Thank you,
Don
So you want to save the regular expression in a global variable?
To do that, you shouldn’t use the quotes, because you now save it as a string instead of a regexp object.
Also, after looking at your regexp, I think the slash is in the wrong place.
This would be the right way to save the regexp:
var csisTest = /^\d{10}$/;
and then in your method you can do this:
if (globals.csisTest.test(vLocation_student)) { ....
Does that work?
Aha!
What I hadn’t understood was that I should not place quotes around it.
What I had was:
var ssidMatch = ‘/^\d{10}$/’;
but what you are saying is,
var ssidMatch = /^\d{10}$/;
…without the quotes.
Thanks so much,
Don