I want to preserve the leading zeros for a number but as usual it trims them.
I tried
<input type="tel" pattern="[0-9]*">
But this allows text input which breaks my case.
Please help!!!
You can use the input type="text", use the ng-pattern to validate your expressions and then use ng-message to validate your field and display errors.
This won't remove your lead 0s.
So your HTML will look something like this:
<input type="text" ng-pattern="[0-9]*" ng-model="myTel">
<div ng-messages="myForm.myTel.$error">
<div ng-message="pattern">You can insert only digits here</div>
</div>
Related
Field should be formatted for SSN.
9 numerical digits only + 2 dashes (XXX-XX-XXXX)
<div class="col-md-6" data-number="0" id="amdCorrSSNcont">
<label for="correctSSN">Correct SSN</label>
<input type="text" placeholder="XXX-XX-XXXX" class="form-control" id="correctSSN">
</div>
How can I format the field ?
Using RegEx is probably the best way. Make sure field max-length is correct, and use the pattern match for ###-##-####
^([0-9]{3}[-]{1}[0-9]{2}[-]{1}[0-9]{4})
A useful tool for creating Regex Patterns is https://regexr.com/
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/>
I want to use masking for Mobile Number in javascript.In this masking, I want to fix (+91) then user can input mobile number(10 digit number)
<label>Phone Number</label>
<input type="button" value="Turn on Mask" id="maskon" />
<input id="phone" type="text" value="" />
$("#maskon").click(function(){
$("#phone").mask("(+91) 9999-999999");
});
If I am using the given masking then I am able to put any digit in place of 9 instead of it I want to have (+91) as fixed.
Is there any idea to solve this problem?
Thanks in Advance!!
I do not think that there is an option for making first few digits fixed for mask plugin.
However you could also write keyup event for textbox and write a regex that verifies that first three digits are +91. You can use this regex for that. /(\+\d{2})/
Within an <input type="text" /> tag how do you I mask the input field so that the user is resricted to the following format [].[] and in between the brackets can be any number of characters.
As an example:
"[Analysis].[Analysis]"
or a another example:
[Analysis-Result].[Analysis Result]"
Use this plugin http://digitalbush.com/projects/masked-input-plugin/#demo