Support Forum Softcomplex logo
About Us  | Services  | Download  | Order  | Support  | |
| Search | Today's Posts | Stats | Board Rules | Not logged in [ Login | Register ]
go to bottom
Last active: Never

Printable Version | Subscribe | Add to Favourites   Post new thread
Author: Subject: how to ignore spaces?
timfitzpatrick
Junior Member

Posts: 3
Registered: 2/10/2005
Member Is Offline
posted on 2/11/2005 at 12:31 AM Reply With Quote
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.
View User's Profile View All Posts By User U2U Member
timfitzpatrick
Junior Member

Posts: 3
Registered: 2/10/2005
Member Is Offline
posted on 2/11/2005 at 05:37 PM Reply With Quote
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++;
}
}
View User's Profile View All Posts By User U2U Member
tigra
Administrator

Posts: 2049
Registered: 6/17/2002
Location: US, CO
Member Is Offline
posted on 2/17/2005 at 07:07 PM Reply With Quote

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
View User's Profile View All Posts By User U2U Member
Post new thread

Related Links:
Product Page Product Page
Product Demonstrations Product Demos
Registration Form Validation
Login Form Validation
Free Download Free Download
Product Documentation Documentation
Documenation Page
Change Log
Validators Comparison Table
Support Forum Support Forum
 

Go To Top


Powered by XMB 1.9.1 Nexus
Developed By Aventure Media & The XMB Group © 2002-2004