简体   繁体   English

8 位电话号码的正则表达式(新加坡号码长度)

[英]Regex for 8 digit phone number (Singapore number length)

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?谁能给我一个简单的正则表达式来验证数字或特定的 8 位正则表达式?

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");}
});

It will allow 0-9 numbers and only 8 digits.它将允许 0-9 个数字和仅 8 个数字。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM