Web Hosting Talk







View Full Version : JavaScript : Form Validation


goolex
10-22-2005, 07:23 AM
Hi

how can i check if user used uppercase letters in a field ?

i have problem with matching characters

Froggy
10-22-2005, 08:21 AM
how can i check if user used uppercase letters in a field ?

Well assuming you know how to get the values of fields in javascript, you could use regular expressions. A more dirty way of doing it would be converting the value to lower case and then comparing it to the origianl value, if they are not equal than it contains upper case.

goolex
10-22-2005, 11:26 AM
i was truing to use maching characters

but with this way it was very easier

thanks ;)

ActivI
10-24-2005, 06:16 PM
regular expressions is the most recomended thing to use :)

Priyanka
10-24-2005, 10:28 PM
No doubt regular expression is the way to go. The other way of doing this can be when user clicks on submit button, the text is converted to upper case by itself. that way user doesnt have to go and insert text again in upper case.

magixman
10-24-2005, 11:15 PM
Originally posted by artin1982
Hi

how can i check if user used uppercase letters in a field ?

i have problem with matching characters

Strictly speaking I believe it would be ....

if (document.formname.fieldname.value.toLowerCase() != x) {
// x has Upper Case Characters
}

hehachris
10-24-2005, 11:33 PM
simply change all the submited value to lowercase...no need to check >> waste time

banner
10-25-2005, 02:26 AM
I probably don't need to mention this, but don't rely solely on client-side javascript validation. If you do, your web application is wide open to malicious input from users who simply disable javascript. Client-side validation has its uses, but it is not a 100% replacement for server-side validation of input.

goolex
10-25-2005, 03:11 AM
thanks all but my problem resolved !

>ActivI yes thats is very easier

>magixman i used this code ;)

>Priyanka & hehachris : yes but i need to user know this , this was username for a special program that it allow only lowercase letters ! so if i change user name to lowercase without notifying user , he will have problem later ;)