Skip to content

Instantly share code, notes, and snippets.

@dudunato
Created April 22, 2021 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dudunato/210d25e49ac2798e7f525d1fbc86b38e to your computer and use it in GitHub Desktop.
Save dudunato/210d25e49ac2798e7f525d1fbc86b38e to your computer and use it in GitHub Desktop.
<lightning:input
aura:id="emailField"
type="email"
label="{!$Label.c.BPEmail}"
value="{!v.payment.email}"
required="true"
onchange="{!c.lowerCaseEmail}"
/>
lowerCaseEmail: function (component, event, helper) {
const emailInput = component.find('emailField');
if ($A.util.isEmpty(emailInput)) return;
const emailValue = component.get('v.payment.email');
component.set('v.payment.email', emailValue.toLowerCase());
if (/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(emailValue)) {
emailInput.setCustomValidity('');
} else {
emailInput.setCustomValidity('Invalid e-mail');
}
},
validateEmail: function (email) {
if (!email || email === '') return false;
// var re = new RegExp('.+@.+\..+');
var re = new RegExp(/^(([0-9a-z]+((\.|\-|\_)[0-9a-z]+)*))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/);
return re.test(email);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment