javascript - Regex for 8 digit phone number (Singapore number length) - Stack Overflow

I'm trying to validate my phone address text field. Can anyone provide me a simple regex to either

I'm trying to validate my phone address text field. Can anyone provide me a simple regex to either validate for numeric digits only or a specific 8 digit regex?

Much thanks!

$('#phone').on('input', function() {
var input = $( this );
var regex = /* regex needed here */
var is_phone = regex.test(input.val());
if (is_phone){input.removeClass("invalid").addClass("valid");}
else {input.removeClass("valid").addClass("invalid");}
});

I'm trying to validate my phone address text field. Can anyone provide me a simple regex to either validate for numeric digits only or a specific 8 digit regex?

Much thanks!

$('#phone').on('input', function() {
var input = $( this );
var regex = /* regex needed here */
var is_phone = regex.test(input.val());
if (is_phone){input.removeClass("invalid").addClass("valid");}
else {input.removeClass("valid").addClass("invalid");}
});
Share Improve this question edited May 9, 2016 at 11:07 georg 215k56 gold badges322 silver badges400 bronze badges asked May 9, 2016 at 11:04 iamhxiamhx 4727 silver badges25 bronze badges 1
  • There are literally thousands of examples out there. The pattern is simple: ^\d{8}$ – Terry Commented May 9, 2016 at 11:08
Add a ment  | 

1 Answer 1

Reset to default 3

It will allow 0-9 numbers and only 8 digits. Try this:

var regex = '/^[0-9]{1,8}$/'; // if you want min 1 and max 8 numbers

var regex = '/^[0-9]{8}$/'; // if you want exact 8 numbers

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745377485a4625066.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信