Can someone define a regex set that would only allow two letters "E" and "P".
I have a web app where certain text areas need to allow entry of just those two characters.
Thank you.
Can someone define a regex set that would only allow two letters "E" and "P".
I have a web app where certain text areas need to allow entry of just those two characters.
Thank you.
/^[ep]+$/
That's it.
^
means "Start of string"[ep]
is our characters "e" and "p"+
means "repeated 1 or more times"$
means "end of string"In case you also want to accept E and P as well, you can add an i
modifier for case-insensitivity:
/^[ep]+$/i
To use in javascript:
var testingRegex = /^[ep]+$/i;
if (testingRegex.match(myString)) {
//Yes, it matches!
} else {
//Error!
}