I have a requirement when there is a username text box and the user can enter the client name to search for the client. And this condition, which the user can add, does a search for wild cards * either infront, or after the client’s name. And the customer name must be at least three characters. I use Regex to validate user input. Now, if the input signal is like "* aaa *". I test this input type with the following regular expression:
[*] {1} ([AZ] | [AZ] | [0-9]) {3} [*] {1}
The code is as follows:
var str = "*aaa*";
var patt = new RegExp("[*]{1}([a-z]|[A-Z]|[0-9]){3,}[*]{1}");
var res = patt.test(str);
alert(res);
Run codeHide result var str = "*aaa***";
var patt = new RegExp("[*]{1}([a-z]|[A-Z]|[0-9]){3,}[*]{1}");
var res = patt.test(str);
alert(res);
Run codeHide result var str = "*aaa*$$$$";
var patt = new RegExp("[*]{1}([a-z]|[A-Z]|[0-9]){3,}[*]{1}");
var res = patt.test(str);
alert(res);
Run codeHide result"* aaa *" res . "* aaa **", "* aaa * $" comimg true. , (* aaa *), . ( "* aaa **", * aaa * $** ..) .
, , ? ?