Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Urgent how to trim the spaces that in the text fileds?

bharathi_reddy
Level 3
Level 3

Hi ,

I have an email field .If a  person enter the value in to the field along with space i need to validate that field by removing spaces.

I already have validation for this email field as shown below..

function isEmailValid(fld){

                    var result = true;

                    if(fld != null){

                              var r = new RegExp();

                        r.compile("^[a-z0-9_\\-\\.\\']+\\@[a-z0-9_\\-\\.]+\\.[a-z]{2,4}$","i");

                              result = r.test(fld.rawValue);

                    }

                    return result;

          }

suggest the best how i will do that

Thanks in advance

Bharathi

1 Reply
_Bruce_Robertson
Level 10
Level 10

Hi Bharathi,

I use this JavaScript function to trim whitespace.

function trimWhitespace(value)              

{

    if (value.replace)

        return value.replace(/^\s*(.*?)\s*$/, '$1');

    else

        return value;

}

Hope it helps,

Bruce