最佳答案在此:
<script lang='JavaScript'>
// e is a element
function validatePattern(e)
{
var pattern = e.pattern;
var testString = trim(e.value);
var re = new RegExp(pattern,"i");
if(testString.match(re)==null)
{
alert(e.errorMessage==null?"Invalid value. Please retype.":e.errorMessage);
e.focus();
return false;
}
return true;
}
</script>
<input type="Text" name="safetyStock" maxlength="4" pattern="^[0-9]+/.{0,1}[0-9]*$" onblur = "return validatePattern(this);" errorMessage="Please input a number.">