View Full Version : Spacing
jvvnmurty
02-22-2007, 08:30 PM
hi,
how we can check with a text having space or not.
i tested it like this:
if(this.abc.getText()=="")
{ body }
else
{
body }
but iam not able to compare.please help me
ebrentnelson
02-24-2007, 06:56 AM
I am assuming you don't want the text to be blank or just a space? I usually run the text through a validator that I wrote that replaces all spaces and then checks to see if it is an empty string... for example,
var Validator = {
string : function( string )
{
if( typeof( string ) != 'string' || string == '' || string.replace( ' ', '' ) == '' )
return false;
else
return true;
}
}
The replace function is not built in, so if you don't have it, then you must include this above the function:
Object.extend = function(destination, source) {
for (property in source) {
destination[property] = source[property];
}
return destination;
}
Object.extend(String.prototype, {
replace : function( from, to )
{
var s = this;
var arr = s.split(from);
return arr.join(to);
}
}
Then you can just say:
if( Validator.string( this.abc.getText() ) )
{ body }
else
{
body }
jvvnmurty
02-26-2007, 11:36 PM
thanks,
it helped me a lot. thanks
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.