javascript - Aadhar Number Format Validation for HTML Textbox - Stack Overflow

I want aadhar number in format of xxxx-xxxx-xxxx. Text box sholud take the input in this format automat

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

Share Improve this question edited Dec 13, 2017 at 22:12 chrki 6,3336 gold badges38 silver badges59 bronze badges asked Nov 22, 2017 at 6:24 VinayVinay 11 gold badge1 silver badge2 bronze badges 3
  • 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
Add a ment  | 

2 Answers 2

Reset to default 0

I 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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信