需要使用正则表达式来验证输入
非常感谢您的帮助
我的代码是
min=3, max=10
MyRegex是
/^(\d{min, max})$/
答案 0 :(得分:0)
我将使用模板字符串:
let min = 2;
let max = 4;
let r = new RegExp(`^\\d{${min},${max}}$`);
[
'2',
'1',
'10',
'aos',
'3333',
'33',
].forEach(s => console.log("%s\t: %s", s, r.test(s)));
答案 1 :(得分:0)
您可以使用模板字符串和RegExp构造函数。
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm");
public static boolean isTimeAfter(Date startTime, Date endTime) {
return !endTime.before(startTime);
}
}
try {
Date inTime = sdf.parse(mEntryTime);
Date outTime = sdf.parse(mExitTime);
if (Config.isTimeAfter(inTime, outTime)) {
//Toast.makeText(AddActivity.this, "Time validation success", Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(AddActivity.this, "Exit time must be greater then entry time", Toast.LENGTH_LONG).show();
}
} catch (ParseException e) {
e.printStackTrace();
//Toast.makeText(AddActivity.this, "Parse error", Toast.LENGTH_LONG).show();
}