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

.sql檔過大無法匯入phpMyAdmin

.sql檔過大無法匯入php...

修改phpMyAdmin資料夾中的config.inc.php檔。 打開後找到下列兩行或自行加入: ...

整合Facebook粉絲專頁的即時訊息,Zotabox網站打造免費線上支援平台。

整合Facebook粉絲專頁...

還記得在msn的年代,msn有提供在網站上架構即時通訊功能,方便網站管理者與user直接交談~ 現在...

DIV區塊內文字左右對齊?

DIV區塊內文字左右對齊?

最近常接到一些英文網站建置的專案....為了讓內容文字能夠左右對齊... 所以我用了以下方式 div...

Recommended reading

Other stories happened at this address

知道自己不夠高,還特地去客廳搬他的寶物箱進來墊著,我是該哭還是該笑呢?

接下來,一團亂....

知道自己不夠高,還特地去客廳...

知道自己不夠高,還特地去客廳搬他的寶物箱進來墊著,我是該哭還是該笑呢? 接下來,一團亂....

鹽烤鯖魚佐高粱

鹽烤鯖魚佐高粱

那年,我為了烤地瓜而買的烤箱,這些年來真的只是為了烤地瓜而存在。 自從上次開箱烤了香魚後,終於也發現...

jQuery效果滑動隱藏

jQuery效果滑動隱藏

因為需要所以紀錄下來,主要是要透過點選按鈕將字串隱藏或顯示出來... 雖說可以直接用hide或是sh...

20170214,我的情人節禮物。

20170214,我的情人節...

,我的情人節禮物。

When caterpillar grow up become butterfly

When caterpill...

When caterpillar grow up become butterfly

是時候吃根香蕉了。

是時候吃根香蕉了。

a 雖說各行各業都有他的辛苦,但我一直覺得農業這種靠天吃飯的工作尤其不容易啊~ 產量太少,價格貴但真...

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