CalcBuilder Forum

How to validate email address field

User moon_1330 2013-11-28 05:01:27

There is a email address filed in my form. I need to validate the email address before calculation and sending email.

I wrote the code in Js event before calculation

var emailaddress = cb_getValue('email');
var filter = /^()+\@(()+\.)+({2,4})+$/;

if (!filter.test(emailaddress)) {
alert('Please provide a valid email address');
}

But after click the button in alert , it still doing calculation and send email to admin. What should I do?


Thank you very much

Moonsoft support 2013-11-28 11:12:09

Hi,
you can add email validation to a text field just typing 'email', at the css class. It will use jquery validator to force the input to be a valid mail format before launching the calculator. You can check how does it work at the video:

Customizing input form

here

http://www.moonsoft.es/en/demo-calcbuilder-en

About
2:20 explains how to introduce the validation you need for your field.

Hope this helps,

User moon_1330 2013-11-28 14:20:56

Thank you very much . It is a great help. It works !

There is another question. I would like to confirm the email in the next field , which means user type the email address must be the same as the previous one they type.

I check the jQuery documentation , there is a "equalTo()" method , so I type " equalTo(variable name)" in the CSS field, but it doesn't work.

Can you help me ? thank you

Jack

Moonsoft support 2013-11-28 17:06:55

Hi,
that jquery method that uses parameters can't be set directly via css property. You can validate manually, for example if your fields are called 'field1' and 'field2', at the js tab execute before calculate execution:


if(cb_getValue('field1')!=cb_getValue('field2')){

alert("wrong!");
return false;
}


Hope this helps, regards

User moon_1330 2013-11-29 03:47:31

Thank you for your help! Calc Builder is great :)

User moon_1330 2013-12-03 08:56:25

Hi mate

There is bug when using the code you provide

When I type the wrong email address in the " Confirm email" field and click the calculate button , it pops up the alert " please enter the same email address"

However , I click reset button and enter the right email address, then click calculator button again , it still pops up the alert

how to solve this problem ? thank you

Moonsoft support 2013-12-03 09:48:30

Hi,
you can try to get the values in a different way, in order to ensure it recovers the actual value of each field:


if(CB("input").val()!=CB("input").val()){


.....



Hope this helps, regards

...
Support/development 40 hours

With the peace of mind of having a professional team at your service (20% discount)

Buy now!
...
Support/development

Perfect for small code changes or to correct any bug at your site

Buy now!