I want aadhar number in format of xxxx-xxxx-xxxx. Text box sholud take the input in this format automatically.
While entering the input the input should automatically convert into this(xxxx-xxxx-xxxx) format.
Only numericals should be accepted.
I want mobile number in format +91(or any other country code)-9999999999(10 digit mobile number).
I have tried /^(?:\(\d{3}\)|\d{3}-)\d{3}-\d{4}$/
, but its not working please help
I want aadhar number in format of xxxx-xxxx-xxxx. Text box sholud take the input in this format automatically.
While entering the input the input should automatically convert into this(xxxx-xxxx-xxxx) format.
Only numericals should be accepted.
I want mobile number in format +91(or any other country code)-9999999999(10 digit mobile number).
I have tried /^(?:\(\d{3}\)|\d{3}-)\d{3}-\d{4}$/
, but its not working please help
-
1
Please share what you have tried with a working snippet using
<>
to demonstrate your issue. – gurvinder372 Commented Nov 22, 2017 at 6:25 - Please post some of your code attempts so people can try to help you. We will not code this for you but we will provide help with your code. – Mark Commented Nov 22, 2017 at 6:25
- /^(?:\\d{4})|\d{4}-\d{4}-\d{4}$/ – R.K.Bhardwaj Commented Nov 22, 2017 at 6:30
2 Answers
Reset to default 0I want aadhar number in format of xxxx-xxxx-xxxx. text box sholud take the input in this format automatically.
One example would be to enforce input to only accept the adhaar number format
$('[data-type="adhaar-number"]').keyup(function() {
var value = $(this).val();
value = value.replace(/\D/g, "").split(/(?:([\d]{4}))/g).filter(s => s.length > 0).join("-");
$(this).val(value);
});
$('[data-type="adhaar-number"]').on("change, blur", function() {
var value = $(this).val();
var maxLength = $(this).attr("maxLength");
if (value.length != maxLength) {
$(this).addClass("highlight-error");
} else {
$(this).removeClass("highlight-error");
}
});
.highlight-error {
border-color: red;
}
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" data-type="adhaar-number" maxLength="19">
I am not interested in giving u everything, but I will point you in the right direction. Use regular expressions.
This regex will help your case but you need to put in your effort on how it must be used in your situation.
console.log(/\d{4}-\d{4}-\d{4}-\d{4}/.test('1000-1000-1000-1002'));
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745502602a4630485.html
评论列表(0条)