/    Sign up×
Community /Pin to ProfileBookmark

Upper Case Letters for Form Validator.Help pls!

Hello everyone i’m having a bit of trouble with the password field i for a login page. I want the Password field to have at least 1 Upper Casse Letter and i don’t know how to add the restrictions [/W]. The javascript code i use can be found here. [URL=”http://www.webcheatsheet.com/javascript/form_validation.php”]http://www.webcheatsheet.com/javascript/form_validation.php[/URL]

[CODE]function validateFormOnSubmit(theForm) {
var reason = “”;

reason += validateUsername(theForm.username);
reason += validatePassword(theForm.password);

if (reason != “”) {
alert(“In order for you to login please fill in the following:n” + reason);
return false;
}

return true;

function validatePassword(fld) {
var error = “”;
var illegalChars = /[W_]/; // this allows only letters and numbers – I want it to also check for at least 1 Upper Case letter.

if (fld.value == “”) {
fld.style.background = ‘Yellow’;
error = “You must enter the password.n”;
} else if ((fld.value.length < 7) || (fld.value.length > 18)) {
error = “You must enter the password.n”;
fld.style.background = ‘Yellow’;
} else if (illegalChars.test(fld.value)) {
error = “Please enter a valid password.n”;
fld.style.background = ‘Yellow’;

} else {
fld.style.background = ‘White’;
}
return error;
}
}[/CODE]

Thanks in advance !

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@cluefulMar 23.2011 — [CODE]else
if ( !/[A-Z]/.test( fld.value ) )
alert( "At least one uppercase letter required" );[/CODE]
Copy linkTweet thisAlerts:
@TaviSFauthorMar 23.2011 — Can't get it to work . Can you please explain in a more newbie language pls ? I'm not that good when it comes to java. Thanks!
Copy linkTweet thisAlerts:
@TaviSFauthorMar 24.2011 — Bump! Anyone ? Thanks.
Copy linkTweet thisAlerts:
@KorMar 24.2011 — Can't get it to work . Can you please explain in a more newbie language pls ? I'm not that good when it comes to java. Thanks![/QUOTE]
It is not Java, it is JavaScript. Different animals. If you don't understand the language, either you start learning it or you hire a coder to do the job.
Copy linkTweet thisAlerts:
@KorMar 24.2011 — <i>
</i>else if (illegalChars.test(fld.value)[COLOR="Blue"]||!/[A-Z]/.test(fld.value)[/COLOR])
Copy linkTweet thisAlerts:
@TaviSFauthorMar 24.2011 — After playing with the Code for several hours and searching for several forum posts i finally found out how to do it on my own . This is what i used.

[CODE]} else if ( (fld.value.search(/[A-Z]+/)==-1) || (fld.value.search(/[0-9]+/)==-1) ) {
error = "Your Password is formed from at least one Upper Case Letter and a Number.n";
fld.style.background = 'Yellow';[/CODE]


Cheers!
Copy linkTweet thisAlerts:
@TaviSFauthorMar 24.2011 — Also Kor script very useful . Thank you for all your help!
×

Success!

Help @TaviSF 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.20,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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