Loading...

如何用javascript判斷字串中必須包含中英文

Temperature: 0 °C

ChungChung
author_tools

字串拆開逐字檢查方式~

首先將每一個字轉換成 ASCII 碼。

在使用for迴圈去檢查每個字是不是在 48-57(0-9) 或 65-90(a-z) 或 97-122(A-Z) 的範圍。

var text='a888888';
var check=[];
check['digit']=0;
check['alpha']=0;
check['others']=0;
for(var i=0;i<text.length;i++){ 
var t=text.charCodeAt(i); 
if(t>=48 && t<=57){ 
check['digit']++; 
}else if(t>=65 && t<=90 || t>=97 && t<=122){ 
check['alpha']++; 
}else{ 
check['others']++; 



if(check['digit']>0 && check['alpha']>0 && check['others']==0){ 
alert('通過檢查'); 
}else{ 
alert('字串內必須含有英文字母及數字'); 


以上紀錄~

台北市內湖區江南街71巷75弄 Go

https://innstory.com/story-如何用javascript判斷字串中必須包含中英文-1264
寫程式筆記

Prev
 如何用javascript接收radio_button被選取後的值

Next
如何使用javascript判斷身分證號跟居留證格式 

Nearby Attractions

台北市內湖區江南街71巷75弄-Nearby Attractions

  • 內湖清代採石場 Go
  • 松山菸廠 Go
  • 孫運璿重慶南路寓所 Go
  • 臺灣大學校門 Go
  • 大稻埕千秋街店屋 Go
  • 臺灣銀行 Go

About the Author

Chung

我是chung
網路工作者
主業是網站系統開發建置
副業是做夢,寫故事
作品請參考/teme.biz
做夢請參考/innstory.com
聯絡/chung.teme@gmail.com

#有人用筆寫日記,有人用歲月寫日記,有人用照片寫日記,而我,用innstory寫日記。

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

將照片加入簽名檔

將照片加入簽名檔

我始終相信,科技來自於人性... 而我的人性則是來自於墮性.... 開發 innstory.com ...

修練中

修練中

假日二胡修練中。

SQL Injection

SQL Injection

SELECT * FROM users WHERE user=&#;aidan&#;...

Recommended reading

Other stories happened at this address

所以兒子,​​​​​​​你希望我待會喝鹹魚咖啡?

所以兒子,​​​​​​​你希...

s 歲個月,開始會跟我搶咖啡喝~ 我說U啊,等你學會怎麼開再來跟我搶吧( ̄∇ ̄) 然後,他開始拿著我...

該來的終究會來

該來的終究會來

終於,蜜月期結束了或者是星期一症候群的延伸? 在去幼稚園一個星期後的今天U還是哭了。 一開始是牽著我...

很久沒畫了~2015年11月29日這是我第一張嘗試畫在手機裡~

很久沒畫了~2015年11月...

s 小時候~喜歡畫畫,但其實是模仿著家姐的腳步~ 我姐姐以前畫畫很灑脫~隨便幾筆、隨便上色~看起來都...

獨自一個人的2個星期,最後幾個小時。

獨自一個人的2個星期,最後幾...

s 終於,獨自一個人的時間~只剩下最後幾個小時.....。 而本該要趕工的案子也差不多完成收尾~在號...

​innstory 更新故事分享功能植入

​innstory 更新故事...

Innstory 更新故事分享功能,花了點時間...但不得不說有時候我真的只是想分享一段文字或幾張照...

清炒青花菜佐尼伯特颱風

清炒青花菜佐尼伯特颱風

青花菜,十字花科,富含豐富維生素C和膳食纖維,還含有具強效抗癌性能的多種營養成分如二吲哚甲烷、維他命...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format