Is there a way to let the user type only three characters? For example, I want to only allow 3
, 6
or 9
in an input text field.
Right-click the text box for which you want to limit characters, and then click Text Box Properties on the shortcut menu. Click the Display tab. Under Options, select the Limit text box to check box, and then specify the number of characters that you want.
You can write a JavaScript form validation script to check whether the required field(s) in the HTML form contains only letters. To get a string contains only letters (both uppercase or lowercase) we use a regular expression (/^[A-Za-z]+$/) which allows only letters.
Option 1 : Put the 3 character prefix outside of the input. This is the best from a user experience perspective. Option 2 : Check for backspace keypress and prevent the delete accordingly.
Here's a way to do it using jQuery: http://jsfiddle.net/ThiefMaster/UZJn2/
<input type="text" maxlength="1" class="only369" />
$('.only369').keyup(function(e) {
if(this.value != '3' && this.value != '6' && this.value != '9') {
this.value = '';
}
});
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