Reputation: 144
I need to valid string with following criteria
Actually, I want to validate samAccountName of Active directory.
I found this but it invalid when using with javascript.
Upvotes: 0
Views: 475
Reputation: 2026
This should work:
var re = /^[^"\[\]:;\|=\+\*\?<>\/\\. ][^"\[\]:;\|=\+\*\?<>\/\\\n\r\t]{0,17}[^"\[\]:;\|=\+\*\?<>\/\\ \n\r\t]$/;
var sourcestring = "source string to match with pattern";
var results = [];
var i = 0;
for (var matches = re.exec(sourcestring); matches != null; matches = re.exec(sourcestring)){
results[i] = matches;
for (var j=0; j<matches.length; j++) {
alert("results["+i+"]["+j+"] = " + results[i][j]);
}
i++;
}
At first it matches exactly one char which isn't in the forbidden group and which isn't " " or ".". Then it matches 0-17 chars which aren't in your forbidden group. At last it matches exactly one char which isn't in the forbidden group and which isn't " " or ".".
So it matches a string from 1-19 chars, which fits the allowed char-group and hasn't a traling space or dot.
Upvotes: 2