问题描述
我有一个输入字段,我只想将其限制为字母数字(AZ,az,0-9)字符,字段的最小长度为5,最大长度最多为15个字符.
I have an input field and I want to limit it to alphanumerical (A-Z, a-z, 0-9) characters only, with a MINIMUM field length of 5, and a maximum length of up to 15 characters total.
有人知道我如何使用jQuery吗?
Does anyone know how I can do this using jQuery?
我正在尝试使用digitalBush的jQuery输入掩码- http://digitalbush. com/projects/masked-input-plugin/
I'm trying to use the jQuery input mask by digitalBush - http://digitalbush.com/projects/masked-input-plugin/
问题在于,除非我输入15个字符,否则该字段将变为空白.如果我在输入字段中输入"012345678912345"(15个字符),则该值将被存储并且可以.
The problem is that UNLESS I enter 15 characters, the field goes blank. If I enter "012345678912345" (15 characters) in the input field then the value is stored and it's fine.
但是,如果我输入"12345"作为用户名,则当该输入框失去焦点时,其值将返回为空白.我可以在定义"或某些选项中进行一些更改来解决此问题吗?
But if I enter "12345" as a username, when that input box loses focus its value goes back to being blank. Is there something that I can change in the "definitions" or options somewhere that fixes this?
非常感谢您的帮助:)
蒂姆
推荐答案
操作如下:'*'是字母数字,在'?'之后是可选的.
This is done like this: The '*' is alphanumeric, anything after the '?' is optional.
jQuery(function($){
$("#elem").mask("*****?**********");
});
这篇关于jQuery输入掩码长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!