Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

js判断长度大于18,小于5,怎么判断。

我想粗略判断一下身份证,就只是这样判断,条件是长度 >18,长度<5,都是不正确的,其他长度都算正确。

 var a = '123456';
 if(a.length>18 || a.length<5){
   alert('身份证号码不正确');
 }else{
   alert('身份证号码正确');
 }

貌似不灵,长度大于5,小于18的,也认为正确,该怎么写呢。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

你写的这个判断 就是a.length在5到18之间为正确啊。。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...