[問題] input 使用 正規 + exec 的問題

看板Ajax作者 (煉)時間9年前 (2014/12/08 17:01), 9年前編輯推噓0(002)
留言2則, 1人參與, 最新討論串1/1
遇到一個問題想請問一下版上先進 我有個 input <input onkeyup="return ValidateFloat(this)" value=''/> function 如下 function ValidateFloat( e ) { if (!/^[???]+$/.test(e.value)) e.value = /^[???]+$/.exec(e.value); } 目的是想要讓使用者只能輸入 英文 or 數字 or _ or - 例如 abc-123_456 -> true 所以問題是想請問 /^[???]+$/.exec(e.value); 這裡應該要怎麼更改呢? 謝謝!! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.173.96.196 ※ 文章網址: http://www.ptt.cc/bbs/Ajax/M.1418029268.A.7D5.html ※ 編輯: kiey (1.173.96.196), 12/08/2014 17:03:53

12/08 17:07, , 1F
使用 /^[a-zA-Z0-9\-\_]+$/ 如果輸入不符合的字串整個 input
12/08 17:07, 1F

12/08 17:07, , 2F
都會變空白
12/08 17:07, 2F
文章代碼(AID): #1KXMZKVL (Ajax)