Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

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

Avatar

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

Avatar

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