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

colorbox 使用 onclick href 驅動

colorbox 使用 on...

colorbox 一直都是很優秀的Lightbox外掛... 目前的網站中幾乎或多或少都會用到Lig...

Android Studio 2.3 隨機改變背景顏色

Android Studio...

class55 開始學習APP 其實我照著工具書上的方式總是在宣告變數時會產生問題~ 例如工具書上寫...

校外教學(木柵動物園)

校外教學(木柵動物園)

期中考週的校外教學,來到了上回去不成的木柵動物園。 炎熱的天,帶著位小蘿蔔頭,一邊觀察一邊完成老師交...

Recommended reading

Other stories happened at this address

凝望

凝望

img窗外,涼風徐徐,不知名的樹木也搖曳著樹枝婆娑起舞。 U不知道看著什麼看到出神,口水都要滴出來了...

街角豆漿店的日常

街角豆漿店的日常

每天,我總會先出門到街角豆漿店吃個早餐,趁著Mandy跟U還在夢鄉~ 一個人,喝著咖啡吃著早餐,浪費...

邁進6個月

邁進6個月

s 兒子在Mandy肚子裡邁入個多月了~ 最近胎動的很厲害,真的辛苦了兒子的媽~ 每天隔著肚皮跟他說...

桌底下的探險

桌底下的探險

拿著我的手電筒像似如獲至寶般的鑽進桌底下。 U開始了他在桌底下的探險。 看著他開心極了的笑臉,倒也覺...

雨天,窩在家裡逗女兒

雨天,窩在家裡逗女兒

雨天,窩在家裡逗女兒

一聽到要帶他出門,馬上給了我一個笑得開懷的笑容~

一聽到要帶他出門,馬上給了我...

一聽到要帶他出門,馬上整裝完畢( ̄∇ ̄) 堅持穿上自己選擇的鞋子,還要自己穿。 堅持背上背包。 堅持...

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