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 (the following two methods are implemented)
<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 to be entered
<input name="username" type="text" onkeyup="value=value.replace(/[^/w=@#]|_/ig,'')">
4. Only English capital letters and numbers are allowed
<input name="name" type="text" value="Enter only capital letters and numbers" 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 = "Here is inputable content";field.restrict = "^Here is content that is prohibited from entering";
The restrict property supports some styles similar to regular expressions:
field.restrict = "a-zA-z"; //Only allow the size letter field.restrict = "a-zA-z"; //Only allow the letters and spaces field.restrict = "0-9"; //Only allow the numbers field.restrict = "^abcdefg"; //Only allow the lowercase letter abcdefg, the field.restrict = "^az"; //All lowercase letters are not allowed, but other contents are allowed, including the uppercase letter field.restrict = "0-9^5"; //Only allow the numbers, but 5 exceptions
Let the restrict character contain letters with special meanings (such as - and ^):
field.restrict = "0-9//-"; //Allow numbers and dash fields.restrict = "0-9//^"; //Allow numbers and ^field.restrict = "0-9////"; //Allow numbers and backslashes
You can also use Unicode to escape sequences to specify allowed content. For example:
field.restrict = "^/u001A";
Note: ActionScript is case sensitive. If the restrict property is set to abc, the uppercase form of letters (A, B and C) will become lowercase form (a, b and c) when inputting, and vice versa. The restrict property only affects what the user can enter, and the script can put any text into the text field.