I don't really know much about regex at all, but if someone could help me change the following code to also allow for lowercase a-z, that would be great!
$("input.code").keyup(function(){ this.value = this.value.match(/[A-Z]{3}([0-9]{1,4})?|[A-Z]{1,3}/)[0]; });
To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" . You also need to use regex \\ to match "\" (back-slash).
[] denotes a character class. () denotes a capturing group. [a-z0-9] -- One character that is in the range of a-z OR 0-9.
Method 1: Match everything after first occurence Whitespace characters include spaces, tabs, linebreaks, etc. while non-whitespace characters include all letters, numbers, and punctuation. So essentially, the \s\S combination matches everything. It's similar to the dot character (.)
If you want a regular expression to be case-insensitive, add a i
modifier to the end of the regex. Like so:
/[A-Z]{3}([0-9]{1,4})?|[A-Z]{1,3}/i
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With