I am not sure if this is possible but what I am trying to accomplish is a text field which would have a character limit of 5 characters if a number field in the same form has 5 entered, or whatever number is entered as the limit.
Is there some way to accomplish this?
yes you can do that
you just need to set maxlength attribute on basis of numeric textbox
$("#txtNumber").keyup(function(){
$("#txtBox").attr("maxlength",$(this).val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="number" id="txtNumber">
<input type="text" id="txtBox">
Related
is there a way to stop users from entering - sign in angular inputs?
Or clear the sign as soon as they entered it?
I don't want values like -1, 9-, 124-5433.
If you only want to accept numeric vaues you can add a min attribute to the html input, like
<input type="number" min="0">
So this won't let you insert negative values.
You can try below way in your input field using oninput I hope it work for you
<input oninput="return event.target.value = event.target.value.replace(/[^0-9]/g,'')" type="text">
I'm currently working for a project in aspx C#, I want to user to type some text (e.g phone number) in text box, while typing in the text field should shows asterisk sign (*) and last 3 digit of the phone number, example : *********810
Any one can help me? Thanks.
You can do this requirement by javascript using regex to replace last 3 digits at event onkeyup of input tag and need a hidden field to keep original value.
function mask(){
//console.log($("#phone").val());
$("#phone").val($("#phone").val().replace(/\d(?=\d{3})/g, "*"));
}
function mask(){
//console.log($("#phone").val());
$("#phone").val($("#phone").val().replace(/\d(?=\d{3})/g, "*"));
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" id="phone" onkeyup="mask()" />
I have one textbox which is of number type. I want it to accept maximum of 16 digits, not more than that. For that I have tried with "maxlength" attribue and "max" attribute both. But its not working. Can anyone provide me solution?
<input type="number" id="dummy" max="16" />
Edit: I need to enter only whole number since it is used for account number of bank.
There are a few of these "how do I further control type="number" fields" questions here on SO. It boils down to:
You make it a type="number" and accept that you can't further mask the input vs. what the browser does to implement a numeric input, or
You make it type="text" and use pattern and/or maxlength to enforce the specific pattern you want, and accept that the browser won't add a specific UI for numbers.
Input type number doesn't support "maxlength" attribute. You can specify "max" attribute (HTML5), which is the highest number user can input. Something like this: <input type="number" max="999999999999" id="dummy" step="1" min="0">.
Edit: Also specify step attribute to 1.
I create a form, where one field should only be filled with numbers.
I want that field can be filled only with numbers since entering input.
Like this example :
How Can I Use Javascript to Allow Only Numbers to Be Entered in a TextBox?
I've tried using Regex, but when I try to input is still able to enter letters.
<input type="number" min="2" pattern="^[0-9]" class="andi_input required-entry" name="amount" id="amount" required title='Only Number' />
I want it when input to field and not after click the Submit button and the message appear and inform that the field can only be filled with numbers.
I also try to add validate-number, but the result is the same.
How, without javascript, so that the field can only be filled with numbers or letters?
Whether for this kind of case have to use JavaScript or is there another way without JavaScript?
HTML 5 uses the type="number" so make sure that the browser that you are using is compatible. Check it out in action here.
You should check browser compatibility.
You're right with <input type="number" pattern="^[0-9]" />.
Your regex rule is :
^[0-9] :
^ assert position at start of the string
[0-9] match a single character present in the list below
(0-9 a single character in the range between 0 and 9)
You can check your regex here.
I use to use HTML5 Validation and jQuery one because IE is capricious most of the time.
UPDATE :
Without Javascript it's not possible to check pattern on real time. I suggest you to use a jQuery library like : http://www.jqueryscript.net/form/jQuery-Plugin-For-Formatting-User-Input-with-Specified-Pattern-formatter-js.html.
Here is a OneLiner:
<input type="number" onkeypress="return /[0-9]/i.test(event.key)">
or
<input type="text" onkeypress="return /[a-z]/i.test(event.key)">
So I have an input form in Angular here:
<input ng-model="sc.zip" class="form-control" maxlength="5" type="text" />
I don't want type="numbers" because the form needs to be a plain empty textbox. However, I only want the user to be able to type numbers. Either I need to detect when the input is not a digit, or be able to search through the box to find non-digits when submitting.
Either way, I need to validate that the form is digits only. Any help would be appreciated!
use regex
<input name="title" type="text" ng-model="sc.zip" ng-pattern="/^[0-9]*$/" required/>