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

Photoshop 曲線文字建置

Photoshop 曲線文字...

Photoshop一直都是很強悍的繪圖軟體。 裡頭的【鋼筆工具】,可以拉貝茲曲線的.... 我剛開始...

分享 (励志短片) 王德顺 《最炫东北人》 完整版 Wang Deshun - Coolest Northeasterner (Inspirational Short Film)

分享 (励志短片) 王德顺 ...

我們都還年輕啊~ 還是可以一直做夢下去的。 只要有夢,我將可以走的更遠。 我是chung 主業做夢,...

Apache無法執行.htaccess?

Apache無法執行.hta...

pexelsphoto5 首先.htaccess是在Apache HTTP Server服務器架設下...

Recommended reading

Other stories happened at this address

小老虎探險~

小老虎探險~

s 住家後頭的小公園,是我們每天都會經過幾次的地方~ 早上,去吃早餐,我們會讓U在這公園小徑上走著。...

5個多月,學會了向後爬行。

5個多月,學會了向後爬行。

個多月,學會了向後爬行。

​​​​​​​Our morning activity: Drawing of finger families

​​​​​​​Our mor...

Our morning activity: Drawing of finger families 早...

悠悠變red

悠悠變red

Mandy鬧著U,沒多久這傢伙雙手抱胸然後說「悠悠變red 」,哼!不開心~ 之後沒多久,又說他變y...

情境Blog

情境Blog

一直都認為,除了文字跟圖片外,應該要有其他的方式來將寫故事時的心情帶給閱讀者。 很久很久以前,我們會...

javascript 底下使用 htmlspecialchars

javascript 底下使...

pexelsphoto Javascript中使用一個函數達到PHP的htmlspecialchar...

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