i dont understand how regex works so this may be is a simple question for many people, but for me is very important that a person can explain me with simple words how can i use this.
i need to validate in jquery adding a new function
$.validator.addMethod("loginRegex",function(a,b){return this.optional(b)||/^[a-zA-Z\d]+$/.test(a)},"Solo se aceptan letras o numeros");
this function accept only letters and numbers, but if you put FH374HD3 the validate return me true, but i need to valid 4 letters and 4 numbers in that order, example: “ABCD4578”, only letters and numbers but 4 letters first and 4 numbers at the end.
is that posible??? tnx all!
This will match a string that is exactly 8 characters long that starts with exactly four letters and is followed by four numbers:
This could also be written as:
with the case insensitivity placed inline.
^matches the beginning of the string[a-z]matches the letters from lower caseato lower casez{4}matches the previous selection 4 times ([a-z][a-z][a-z][a-z]but in fewer characters)\dmatches digits (equivalent to[0-9]){4}is as above (\d\d\d\dbut in fewer characters)$matches the end of the stringiis the case-insensitivity flag so that[a-z]matches for capital letters as well.It should also be noted that this will not match for special characters such as é or à as they are not in the range
[a-z].