【发布时间】:2016-05-22 02:38:09
【问题描述】:
我们有一个 magento 电子商务网站。
我们需要以下代码的验证支持只有数字
<input type="text" onkeydown="limit(this);" onkeyup="limit(this); "title="<?php echo $this->__('Zip/Postal Code') ?>"
name="billing[postcode]" id="billing:postcode"
value="<?php echo $this->escapeHtml($this->getAddress()->getPostcode()) ?>"
class="input-text validate-zip-international
<?php echo $this->helper('customer/address')->getAttributeValidationClass('postcode') ?>" placeholder="Postal code"/>
JS
function limit(element)
{
var max_chars = 6;
if(element.value.length > max_chars) {
element.value = element.value.substr(0, max_chars);
}
}
现在它只限制数字,但是当我们输入字母时,光标向上移动。我也想删除最后出现的增量按钮
【问题讨论】:
-
你为什么不使用
<input type="number" max="999999" min="0" />? -
您也可以使用
input type="tel"进行数字验证,您可以使用以下正则表达式:/^\d$/
标签: javascript