2017-06-22 131 views
0

我想設置驗證密碼字段包含:有特殊字符Angular2密碼驗證

兩個大寫字母,小寫字母,數字和特殊字符

這是我有這麼遠:

passwordValueValidator(control) { 
    if (control.value != undefined) { 
    if (!control.value.match(/^(?=.*[0-9])[[email protected]#$%^&*]{6,100}$/)) { 
     return { 'invalidPassword': true }; 
    } 
    else{ 
     //here i need to add check for special characters 
    } 
    } 
} 

上述代碼僅適用於字母和數字組合。做些什麼我需要添加到還檢查用戶輸入特殊字符

特殊字符:[email protected]#$%^&*()_+(按shift +數字0-10照耀處)

回答

2

試試這個: /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[[email protected]#\$%\^&\*])(?=.{6,100})/

+0

真棒它的作品 –