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的日期加減運算

PHP的日期加減運算

在再加上5天 = $years = date("Y"); //用date()函式...

在PHP裡面如何做到基本的SQL injection防禦?

在PHP裡面如何做到基本的S...

資訊安全一直是很頭痛的問題....我一直以來也在尋找最好的方式... 但在尋找的過程中...至少也得...

Android Studio 2.3 陽春型計算機

Android Studio...

andrio55 原本這次的學習課題是,與使用者互動之「按一下」事件處理。 我按照工具書上寫的,完成...

Recommended reading

Other stories happened at this address

日是好日,年是好年,2017年新年快樂!!

日是好日,年是好年,2017...

即將到來的年會是個什麼樣的年呢? 年的日子,家裡有了新成員~ 而我,當了爸爸。 對我的人生來說~是個...

PDO連接Mysql方式 MVC上應用

PDO連接Mysql方式 M...

pexelsphoto 將連結資料庫的方式加入model function connect() { ...

有些事不堅持就會被遺忘

有些事不堅持就會被遺忘

s 這陣子,忙著趕工專案、忙著DBUG、忙著對陌生的技術找答案。 忘了記錄故事..............

獨自一個人的2個星期,第5晚意外的訪客。

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

s 雖說感受不到泰莉的威脅,但仍下了整天的雨。 今天的工作心超級不順,倒不是說遇到了甚麼特別的問題。...

我覺得我今晚的豬肉炒的不錯~

我覺得我今晚的豬肉炒的不錯~...

我覺得我今晚的豬肉炒的不錯~

邁進6個月

邁進6個月

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

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