1. Only numbers are allowed.
<input name="username" type="text" onkeyup="value=this.value.replace(/\D+/g,'')">
2. Only English letters, numbers, and underscores (_) are allowed)
<input name="username" type="text" style="ime-mode:disabled"><input name="username" type="text" onkeyup="value=value.replace(/[^\w\.\/]/ig,'')">
3. Only English letters, numbers, and = @ # are allowed @#
<input name="username" type="text" onkeyup="value=value.replace(/[^\w=@#]|_/ig,'')">
4. Only uppercase letters and numbers are allowed.
<Input name = "name" type = "text" value = "only uppercase letters and numbers are input." style = "color: gray" onfocus = "this. value = ''; this. style. color = 'black' "onkeyup =" this. value = this. value. replace (/[^ A-Z0-9]/gi, ''); this. value = this. value. toLocaleUpperCase ();
5. Only Chinese characters are allowed.
<input name="username" type="text" onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')">
[Filter text input]
TextField. restrict = "this is input content"; field. restrict = "^ this is forbidden content ";
The restrict attribute supports regular expressions:
Field. restrict = "a-zA-z"; // only the field size is allowed. restrict = "a-zA-z"; // only letters and spaces are allowed. restrict = "0-9"; // only the number field is allowed. restrict = "^ abcdefg"; // field is allowed except for the lowercase letter abcdefg. restrict = "^ a-z"; // all lower-case letters are not allowed, but other contents are allowed, including field, an upper-case letter. restrict = "0-9 ^ 5"; // only numbers are allowed, except for 5
Make the restrict character contain special letters (such as-and ^ ):
Field. restrict = "0-9 \-"; // allows numbers and broken Number Fields. restrict = "0-9 \ ^"; // allow numbers and ^ field. restrict = "0-9 \\\\"; // allow numbers and backslash
You can also use the Unicode escape sequence to specify the allowed content. For example:
field.restrict = "^\u001A";
Note: ActionScript is case-sensitive. If the restrict attribute is set to abc, uppercase letters (A, B, and C) are allowed, B and c), and vice versa. the restrict attribute only affects the content that users can enter. The script can put any text into text fields.