The CreatorCon Call for Content is officially open! Get started here.

regex is correct but some issue in the script

Community Alums
Not applicable

Hi,

I wrote the regex for validating the email ID, but the problem is coming with respect to the code. Kindly help.

 

function onSubmit() {

	var email_ID = g_form.getValue("email");
	
	
		var testEmail = /^([a-z0-9A-Z\_\.]*)@([a-z\.]*)$/;

		if (!testEmail.test(email_ID)) {
			g_form.addErrorMessage("invalid email");
			return false;
		}
		return true;

 

Regards

Suman P.

12 REPLIES 12

DrewW
Mega Sage

It would help to know what the error message is.  I'm assuming you did not paste all of the code since you are missing a "}" at the end and its not really formatted well.

 

 

 

Community Alums
Not applicable

Hi @DrewW ,

 

Here is the complete script formatted. It is showing error even for proper format ones

 

 

function onSubmit() {

    var email_ID = g_form.getValue("email");
    var testEmail = /^([a-z0-9A-Z\_\.]*)@([a-z\.]*)$/;
    if (!testEmail.test(email_ID)) {
        g_form.addErrorMessage("invalid email");
        return false;
    }
    return true;
}

 

 

Regards

Suman P.

Sounds like you need to check your RegEx like @maroon_byte is mentioning.

 

Community Alums
Not applicable

Hi @DrewW and @maroon_byte ,

My exact requirement is I can have as many a-z, A-Z, 0-9 before @. Then after that, it should only accept small letters.

So, I tried to update it like this. Still doesn't work.

 

function onSubmit() {

    var email_ID = g_form.getValue("email");
    var testEmail = /^([a-z0-9A-Z\_\.]*)@([a-z]*)+\.[a-z]*$/;
    if (!testEmail.test(email_ID)) {
        g_form.addErrorMessage("invalid email");
        return false;
    }
    return true;
}

 Regards

Suman P.