timfitzpatrick
Junior Member
Posts: 3
Registered: 2/10/2005
Member Is Offline
|
| posted on 2/11/2005 at 12:31 AM |
|
|
how to ignore spaces?
A tester found that if you simply put a space in a field that's being validated, it validates... how can we ignore spaces if that's all
there is? Spaces SHOULD be allowed within other content... i.e.
"my name" is ok, " " is not.
|
|
|
timfitzpatrick
Junior Member
Posts: 3
Registered: 2/10/2005
Member Is Offline
|
| posted on 2/11/2005 at 05:37 PM |
|
|
Here's a fix
I managed to add a fix to the script to account for this... here it is if anyone wants it. SoftComplex, feel free to add it:
I added these lines under the "check length" section:
// check to see if it's all white space
else if (String(this.a_fields[n_key]['v']).length > 0) {
var space = ' ';
// assume that string is all spaces
var spflag = 1;
// loop through string and stop if anything other than white space found
for (var i=0; i < String(this.a_fields[n_key]['v']).length; i++) {
if (space.indexOf(String(this.a_fields[n_key]['v']).charAt(i)) == -1) {
spflag = 0;
break;
}
}
if (spflag != 0) {
this.a_fields[n_key].n_error = 1;
n_errors_count++;
}
}
|
|
|
tigra
Administrator
Posts: 1990
Registered: 6/17/2002
Location: US, CO
Member Is Offline
|
| posted on 2/17/2005 at 07:07 PM |
|
|
ok, we improved the code so all whitespaces at the beginning and at the end of the values are removed. With regular expressions whole thing is in one
line:
this.a_fields[n_key]['v'] = s_value.replace(/(^\s+)|(\s+$)/g, '');
available since v1.2
|
|
|