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

PHP數字1000分位逗號分隔函數number_format()

PHP數字1000分位逗號分...

有時候我們必需將數字加上每三個位數加上一個逗號(千分位),例如變成,,我雖不常用...但偶爾要用到時...

apache下設置不顯示目錄列表 Indexes FollowSymLinks

apache下設置不顯示目錄...

pexelsphoto5 選擇編輯httpd.conf文件 vi conf/httpd.conf 找...

判斷捲軸的位置

判斷捲軸的位置

當捲軸往下移動時,判段目前移動到哪個位置... Javascript部份 $(function(){...

Recommended reading

Other stories happened at this address

1歲6個多月,小小孩愛學大人樣~

1歲6個多月,小小孩愛學大人...

歲個多月,小小孩愛學大人樣~

apache下設置不顯示目錄列表 Indexes FollowSymLinks

apache下設置不顯示目錄...

pexelsphoto 選擇編輯httpd.conf文件 vi conf/httpd.conf 找到...

獨自一個人的2個星期,第4晚,還好有屏東帶回來的三層肉(蔥爆蕃茄豬肉片)。

獨自一個人的2個星期,第4晚...

s 其實,從昨晚我就已經知道今天晚上要炒個豬肉片來當晚餐。 說實在的,以往單身的日子我鮮少自己下廚。...

植入章節的功能

植入章節的功能

在寫故事的時候,我常會有機會跳著寫~ 例如寫下旅遊記事時,寫了第一天,正準備要寫第二天時卻因為剛好有...

父子時間,萬聖節小物DIY

父子時間,萬聖節小物DIY

父子時間,萬聖節小物DIY

敬逝去的青春~

敬逝去的青春~

那年.........。 我們一起打工,派發著建設公司的傳單,腳下的摩托車跑遍萬巒、潮州、內埔、三地...

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