url
缺點不支持中文URL:
(http[s]{0,1}|ftp)://[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?
實例:
var regexp = new RegExp("(http[s]{0,1}|ftp)://[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?", "gi");
var urls = textbox.value.match(regexp) || [];//textbox爲文本框
console.log(urls);
小時
str = str.match(/^(?:0?[0-9]|1[0-9]|2[0-4])$/);
if (str == null) alert("小時格式不正確");分鐘
str = str.match(/^[0-5]?[0-9]$/);
if (str == null) alert("分鐘格式不正確");
數字
this.value = this.value.replace(/[^\d]/g,""); //清除“數字”和“.”以外的字符
this.value = this.value.replace(/^\./g,""); //驗證第一個字符是數字而不是.
this.value = this.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
數字和小數點
this.value = this.value.replace(/[^\d.]/g,""); //清除“數字”和“.”以外的字符
this.value = this.value.replace(/^\./g,""); //驗證第一個字符是數字而不是.
this.value = this.value.replace(/\.{2,}/g,"."); //只保留第一個. 清除多餘的.
this.value = this.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");