calling a trim method in actionscript 2.0
        Posted  
        
            by user151013
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user151013
        
        
        
        Published on 2009-09-09T08:00:38Z
        Indexed on 
            2010/06/12
            9:13 UTC
        
        
        Read the original article
        Hit count: 203
        
actionscript
Hi I Got a notnull function for a text field as below
private function valStringNotNull( val:String ) :Boolean
    {
    	if ( String(val).length <= 0 )
    	{
    		_errorCode = "StringNull";
    		return false;
    	}
    	_errorCode = "NoError";
    	return true;
    }
and this function is being called here
var pCnt:Number = 0;
  _validateParams[pCnt++] = { type: "notNull",  input: win.firstNameInput , isSendData:true, dataName:"firstName"};
  _validateParams[pCnt++] = { type: "notNull",  input: win.lastNameInput, isSendData:true, dataName:"lastName"};
  _validateParams[pCnt++] = { type: "noValidation", input: roleCombo, isSendData:true, dataName:"role" };
  Selection.setFocus(win.firstNameInput);
and for the not null I defined this way
private function validateCases ( param:Object ) :Boolean
 {
  _errorObj = param.input || param.input1;
  switch( param.type )
  {
                 case "notNull":
    return valStringNotNull( param.input.text );
   break;
                       }
 }
but as you see as I defined the length should be greater than zero its taking even a space as an input and displaying blank white space in my text field so I got a trim function as below
public function ltrim(input:String):String
    {
    	var size:Number = input.length;
    	for(var i:Number = 0; i < size; i++)
    	{
    		if(input.charCodeAt(i) > 32)
    		{
    			return input.substring(i);
    		}
    	}
    	return "";
    }
and I need to call this trim function before my not null function so that it trims off all the leftside white space but as I am very new to flash can some one help me how to keep this trim function before the notnull function.Can some one please help me with this please
© Stack Overflow or respective owner