/    Sign up×
Community /Pin to ProfileBookmark

Form validation and regular expressions

Hello
I have one problem in form validation using java scripts and regular expressions. I want to have a regulation that if the password contains more than 3 similar characters, it returns an error on indicating the weakness of the password.
The part of the java script concerned is as follow:

re = /.{0,3}/;
if(re.test(myForm.npassword.value)){
alert(“Error: The password can not contain more than 3 similar characters.”);
return false;
}

But it doesn’t work , any comment plz?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Oct 31.2006 — Um, . means any character except new line so that means abc aaa cda would all test true. You probably also want to use match and charAt()

Eric
Copy linkTweet thisAlerts:
@semi-sentientOct 31.2006 — If you want to discount case-sensitivity, then convert the string to lower case. The following regex will return true if the user inputs "aaa" and "AAA" (or any other letter of the alphabet):

<script language="javascript" type="text/javascript">
// will fail because of the "fff"
var pwString = "Aaa@@1.222bce-fff";

if (pwString.match(/([a-zA-Z])11/)) {
alert("Your password can not contain 3 or more consecutive identical characters.");
}
</script>
Copy linkTweet thisAlerts:
@azadehauthorOct 31.2006 — Thanks .I used the regular expression u gave me and it works perfectly
×

Success!

Help @azadeh spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...