I am evaluating if the email input is empty or if its not the right pattern. If it is so the emailError is getting value true and further code doesn't execute
if(typeof($rootScope.email) === 'undefined' || /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($scope.email)){
$scope.emailError = true;
}
It evaluates the empty input but doesn't check the pattern correctly. Where did I go wrong?
Edit: The html part looks like so:
<input ng-class="{true:'error-bron', false:'nonerror-bron'}[emailError===true]" ng-if="$root.lang ==='en'" type="email" maxlength="40" required class="bron-input" placeholder="Email" ng-model="$root.email"/>
After that it goes into function if all the fields are valid:
if(!$scope.nameError && !$scope.emailError && !$scope.phoneError){
If I put the pattern validation inside html then it checks it fine on the first time but after the form has been submitted and the user decides to open the pop up again then the values are initially valid and the user can send even an empty email. Hence why Id like to check it inside this function that is executed when user presses submit button.