Created
April 22, 2021 18:35
-
-
Save dudunato/210d25e49ac2798e7f525d1fbc86b38e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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