如果文本中存在大写或数字,则test返回false

时间:2018-01-29 04:45:20

标签: javascript angularjs regex

regexp我尝试过include(对于大写)。以下返回true

self.upperCharCheck = false ; //has to be false by default
var temp ="(?=(.*[^A-Z]))";
self.testUpperCase = new RegExp(temp);
self.upperCharCheck = (self.testUpperCase.test(self.newPassword));

如果没有UpperCase,我希望self.upperCharCheck为true,否则如果存在大写则为false。

1 个答案:

答案 0 :(得分:3)

/[A-Z0-9]/应该是检查字符串是否包含大写字母或数字所需的全部内容:

var upperRegex = /[A-Z0-9]/;

console.log(upperRegex.test('should be false'));
console.log(upperRegex.test('should be True'));
console.log(upperRegex.test('should also 0 be true'));

console.log('===');
//This will return false if an uppercase letter or a number is in the string
var upperRegex2 = /^[^A-Z0-9]+$/;

console.log(upperRegex2.test('should be true'));
console.log(upperRegex2.test('should be False'));
console.log(upperRegex2.test('should also 0 be false'));