Expand my Community achievements bar.

Urgent !!! How to trim spaces of an email filed ?

Avatar

Level 3

Hi,

I have an email field in a form ,which have a validation at the time of submission of form as shown in the 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;

          }

but if user by mistakely enters the space in that field  at the time of validation it is  showing an error called "Invalid Email Format"

I need to trim those spaces either modifying the above regular expression or the best way

Please suggest ..

Thanks in Advance

Bharathi

1 Reply

Avatar

Level 8

In the exit event of your email field put:

this.rawValue = this.rawValue.replace(/\s/g,"");

Kyle