Hi Eduardo,
Thanks for the replying to my post. I appreciate the help. I was
looking over the regular expressions as you suggested and got the check for
whitespace and numbers to work, but I am having difficulty validating
against irregular characters, i.e., !#$%^&*()+=?).
I'm using the function listed below to validate the form fields. So, if I
wanted to validate against irregular characters, what regular expression
could I use to check for the following irregular characters: !#$%^&*()+=?).
Thanks again for your help! I'm pretty new with Javascript, so I really
appreciate the help on this.
function noNumbers(field) {
if (field.value.match(/\d/)) {
alert('This field can not contain numbers!');
field.focus();
field.select();
return false;
}
return true;
}
-D-
"edoardo" <ed*************@interfree.it> wrote in message
news:85**************************@posting.google.c om...
"Dwayne Epps" <dw**************@centurytel.net> wrote in message
news:<5T********************@feed2.centurytel.net> ...
I've created a function that checks form fields that only will have
letters. This is the script:
<script type="text/javascript" language="javascript">
function validateString(field, msg, min, max) {
if (!min) { min = 1 }
if (!max) { max = 65535}
if (!field.value || field.value.length < min || field.value.max > max) {
alert(msg);
field.focus();
field.select();
return false;
}
return true;
}
</script>
How can I add code to this function that checks for whitespace...ex.
"\n\r\t"
I would also like to check for only letters in the fields and make sure
no numbers have been entered. Any help is appreciated. Thanks in advance.
-D-
Hi!
Well, did you know the regular expressions?!
Take a look!
funcion noNumbers( field ) {
if( field.value.match( /\d/ ) {
alert('The string MUST not contain numbers!');
}
}
function removeSpaces( field ) {
field.value.replace( /\s/g, '' );
}
Here are some useful regular expressions:
[a-zA-Z] any letter
\d any number; same as [0-9]
\D any NOT number; same as [^0-9]
\w any alphanumeric character; same as [a-zA-Z-0-9_]
\W any NON-alphanumeric character; same as [^a-zA-Z0-9_]
\s any whitespace (tab, space, newline, etc...)
\S any NON-whitespace
\n newline
\t tab
Try search informations about regular expressions in JavaScript!
HTH
--
Edoardo
[http://edoardoontheweb.interfree.it/index.html]