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

Html編輯器Ckeditor 4.0內容讀取與寫入方式

Html編輯器Ckedito...

ckor 在Html編輯器裡,Ckor功能很強大雖然好用....但還是有很多部份需要微調啊... 原...

Google map 功能導入

Google map 功能導...

blogmap 寫故事還是得有地圖才好厚! 前幾天,sam同我說有一個客戶有Google map的需...

JavaScript的獲取日期代碼不足兩位數補0

JavaScript的獲取日...

當我們用javascript得到了一個時間後...針對月份及日期的部分只會顯示數字... funct...

Recommended reading

Other stories happened at this address

原來種九層塔並不需要種子啊~

原來種九層塔並不需要種子啊~...

我真的很愛九層塔的香味~ 在台灣,從小吃鹹酥雞到家庭料理九層塔煎蛋都少不了這一味。 當然更別說是南洋...

這是~菠蘿麵包.....

這是~菠蘿麵包.....

我記得我買的是菠蘿麵包..... 怎麼被U吃過後,突然覺得這麵包很可憐啊~~~ 這傢伙只給我拔下那金...

突然覺得,若沒有鍵盤我可能永遠都想不起我的密碼....。

突然覺得,若沒有鍵盤我可能永...

s 你有沒有過,怎麼想都想不起來的密碼~ 只要坐在電腦前就很自然的敲了出來⊙⊙ 突然覺得,若沒有鍵盤...

你是否知道我故事中的角色?

你是否知道我故事中的角色?

那天~突然在想....... 有看我故事的人,是否會知道我寫的那些故事裡,裏頭的人事物對我有何意義?...

Apache無法執行.htaccess?

Apache無法執行.hta...

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

小黃瓜拌炒豬肉片佐高粱

小黃瓜拌炒豬肉片佐高粱

s 最近氣候多變,有時候冷得不像話~ 因此,原本想要拿來涼拌的小黃瓜,也改變了製作方式~用炒的( ̄∇...

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