【发布时间】:2017-08-21 05:37:01
【问题描述】:
我想验证用户名是否已存在于我的数据库中。这是我的代码:`
import { FormControl } from '@angular/forms';
export class EmailValidator {
static checkEmail(control: FormControl): any {
return new Promise(resolve => {
let EMAIL_REGEXP = /^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i;
if (control.value != "" && (control.value.length <= 5 || !EMAIL_REGEXP.test(control.value))) {
resolve({
"Please provide a valid email": true
});
}else if(control.value.toLowerCase() === "sample123@yahoo.com"){
resolve({
"email taken": true
});
}else {
resolve(null);
}
});
}
}
希望你能帮助我。提前致谢。
【问题讨论】:
-
else if(control.value.toLowerCase() === "sample123@yahoo.com") 此代码检查 sample123@yahoo.com 是否永远无法使用。我想从我的 API 中替换它。
-
不,MySQL。我有 API。
标签: angular api validation ionic2