box1中的正則表達式起作用,然後我在box2中添加正則表達式,並將其轉換爲我的用法 - 它看起來前方,不會讓用戶輸入前導空格。當我替換括號中的字符時,我得到了警告/錯誤(在日食中) - 我嘗試過轉義第一個字符 ,但那不能解決它 - 我有「逃脫」問題?謝謝您的幫助!HTML輸入字段項目預讀REGEX Javascript
if (v.match(/^\d{2}$/) !== null) works
try (v.match(^(?!\s)([a-zA-Z0-9 _.'"()!?&@]){1,}$) !== null) fails
(v.match(/^(?!\s)([a-zA-Z0-9 _.'"()!?&@]){1,}$) !== null) fails
errors undefined attribute name null
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
Typical InputBox1
<input type="text" name="date" onkeyup="var v = this.value;
if (v.match(/^\d{2}$/) !== null) {this.value = v + '/';}
else if (v.match(/^\d{2}\/\d{2}$/) !== null) {this.value = v + '/';}"
maxlength="10">
<br>
Typical InputBox2
<input type="text" name="date" onkeyup="var v = this.value;
if (v.match(^(?!\s)([a-zA-Z0-9 _.'"()!?&@]){1,}$) !== null) {this.value = v + '/';}
else if (v.match(^(?!\s)([a-zA-Z0-9 _.'"()!?&@]){1,}$) !== null) {this.value = v + '/';}"
maxlength="10">
<!-- ^(?!\s)([a-zA-Z0-9 _.'"()!?&@]){1,}$ lookahead for leading blank space -->
</body>
</html>
我在網上測試了正則表達式,它似乎工作正常 - 你的建議並沒有解決它 - 似乎有很多逃避要做 - 我仔細嘗試,但仍然錯誤 – Tom
需要轉義\。 + *? [^] $(){} =! < > | : - – Tom
else if(v.match(\^\(\?\!\\ s \)\(\ [a \ -zA \ -Z0 \ -9 _ \。'「\(\)\!\? &#\] \)\ {1,\} \ $)!== null){this.value = v +'/';}「 maxlength =」10「> – Tom