[英]How to match password and confirm password with regex validation for uppercase and number
[英]How to create validation with 2 uppercase letter and number?
假設這是學生 ID CC201801194
,我想限制輸入像這樣的小寫字母cc20181194
。 它們應該只輸入 2 個字符串 9 個數字。
這就是我得到的:
$.validator.addMethod("noCaps", function(value, element) {
return this.optional(element) || /[A-Z]{2}/.test(value);
});
可以使用模式屬性在 HTML 標記(沒有任何 JS)中直接實現。
<input type="text" pattern="[A-Z]{2}[0-9]{9}">
input + span:after { position: absolute; padding-left: 5px; } p.hint { display: none; } input:valid + span:after { content: "✓"; } input:placeholder-shown + span:after{ content: ""; } input:invalid + span:after { content: "✖"; } input:invalid + span + p.hint { display: block; }
<form> <input type="text" pattern="[AZ]{2}[0-9]{9}" Placeholder="Student ID"> <span class="validity"></span> <p class="hint">Student ID must be 2 capitals and 9 numbers.</p> </form>
嘗試這個:
$.validator.addMethod("noCaps", function(value, element) {
return this.optional(element) || /[A-Z]{2}[0-9]{9}/.test(value);
});
嘗試這個:
$("#...").keydown(function(e) {
var test = /[A-Z]{2}[0-9]{9}/; //regex
//...
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.