Does anyone have a good email regex that works in Ionic? Because I am struggling to find one. This is my current one:
^[a-zA-Z0-9._]+[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$
but it accepts some wrong stuff like whatever@gmail
Does anyone have a good email regex that works in Ionic? Because I am struggling to find one. This is my current one:
^[a-zA-Z0-9._]+[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$
but it accepts some wrong stuff like whatever@gmail
I’ve all the validation control on a different service. This is my function
// SINGLE FIELD VALIDATORS
export function emailValidator(control: FormControl): {[key: string]: any} {
var emailRegexp = /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
if (control.value && !emailRegexp.test(control.value)) {
return { invalidEmail: true };
}
}
This is what i use:
let EMAIL_REGEXP = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[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,}))$/;
none of them works for me
they don’t accept my correct address
how is this working for you?
I have tested it here:
http://regexr.com/
and it doesn’t work
This seems to work fine for me up to now
Validators.pattern("[a-zA-Z0-9\.\_-]{1,}@[a-zA-Z0-9\.\_-]{1,}[a-zA-Z]{2,}")
this one is worse than the one I have posted
this is the same regex as you posted? because it doesn’t look same
Yep it’s the same copy pasted from here
but I am copy-pasting it there and it gives no match
response
^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[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,}))$
could you please answer?
Don’'t know what to tell you just tested again
^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[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,}))$
Can you please explain, in what way worse?
what the hell, we are both testing the same regex, on same site, and we have different results? how is this possible
lol maybe try to test inside your app or use another site ?
https://www.regextester.com/
i have found out what was wrong on this site-testing
but still, it doesn’t work in my app, this is weird, i use it like this:
this.signupForm = formBuilder.group({
email: ['', Validators.compose([Validators.pattern('^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[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,}))$'), Validators.required])]
});
am i doing this right?
Make a custom validator and use it in your page
import {FormControl} from '@angular/forms';
export class EmailValidator {
static isInvalidEmailFormat(control: FormControl){
let EMAIL_REGEXP = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[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,}))$/;
if (control.value != "" && (control.value.length <= 5 || !EMAIL_REGEXP.test(control.value))) {
return { "isInvalidEmailFormat": true };
}
return null;
}
}
email : ['', Validators.compose([EmailValidator.isInvalidEmailFormat, Validators.required])],
with this i have an error that control.value
is undefined
edit: nvm i have fixed this, and now to my surprise regex is working as well