freesoul
freesoul

Reputation: 246

Form validation to check repetition in string

I want to check the entered string in text-box for repetition. i.e. I want to accept only those String which have no repetition and can have all alphabets (CAPS ON & off) + special characters and all digits? I tried this regexp for checking repetition

var pattern = /(\d).*\1/;

and as everything is allowed when it comes to range so i did not make any check for the same but it is not working. Can anyone help me out with something that can make my Spin. :-)

Example - vCc@#^k->Valid VbhUiu->Valid mnkOOp->Invalid fgty^^m->Invalid

Upvotes: 0

Views: 451

Answers (1)

Barmar
Barmar

Reputation: 782130

var pattern = /(.).*\1/;
if (pattern.test(str)) {
    alert("No repetition allowed");
} else {
    alert("Looks good!");
}

DEMO

Upvotes: 1

Related Questions