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
  • 福州街11號日式宿舍 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

圖文穿插效果

圖文穿插效果

寫故事還是得圖文穿插看起來方便些~ 其實一直都在找最適合寫故事的方式,一開始我把所有上傳照片都放在故...

解決png圖檔GD合圖後背景色塊問題

解決png圖檔GD合圖後背景...

重點在於設定圖片走透明通道~ $img = imagecreatefrompng($src); im...

戶外教學到板橋派出所,當一日小警察。

戶外教學到板橋派出所,當一日...

差婆來了。

Recommended reading

Other stories happened at this address

5U的第1張生日卡片

5U的第1張生日卡片

s U的第張生日卡片,謝謝威廷跟瓊慧的用心。 U也謝謝威廷姊夫跟瓊慧姊姊\(^o^)/ 感覺這週是U...

一家人平平安安最幸福

一家人平平安安最幸福

一家人平平安安最幸福

第一次吃副食品,你這表情也太有戲了吧!! 是有難吃到這樣嗎?

第一次吃副食品,你這表情也太...

第一次吃副食品,你這表情也太有戲了吧!! 是有難吃到這樣嗎?

5U要上學囉~

5U要上學囉~

U要上學囉~ 早上拿到書包就這樣背著一整天。 看起來是很開心,就是不知道等真正的那一天到來他會是甚麼...

Linux底下Apache啟動、停止、重啟指令

Linux底下Apache啟...

a 如果apache安裝成為linux的服務的話,可以用以下命令操作: service httpd ...

爸爸媽媽你看~rainbow

爸爸媽媽你看~rainbow...

看著U排著字母色筆,當然這已經不是他第一次排列。 我跟Mandy只是在旁回應著他的呼喚,爸爸你看、媽...

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