在 CoffeeScript 中提交表单时不允许在文本字段中使用十进制数字
Do not allow decimal numbers in textfield on form submittion in CoffeeScript
我有一个 HTML 形式的文本字段。在提交表单时,我想提示用户是否输入了十进制数。我如何在 coffeescript 中使用正则表达式来做到这一点?
jQuery('form#adjustment_invoice_form input[type=submit]').live 'click', ->
if !(/[^0-9]/.test(adj_value))
alert("Decimal numbers are not allowed for")
false
我不允许小数 .
字符:
jQuery(document).ready(function () {
jQuery(".no_decimal").keydown(function (e) {
if (e.keyCode == 190)
return false;
});
});
CoffeeScript 中的上述内容:
jQuery(document).ready ->
jQuery('.no_decimal').keydown (e) ->
if e.keyCode == 190
return false
return
return
如果您仍然坚持只检查表单提交,请使用:
if adj_value.indexOf('.') != -1
alert("Decimal numbers are not allowed for")
return false
我有一个 HTML 形式的文本字段。在提交表单时,我想提示用户是否输入了十进制数。我如何在 coffeescript 中使用正则表达式来做到这一点?
jQuery('form#adjustment_invoice_form input[type=submit]').live 'click', ->
if !(/[^0-9]/.test(adj_value))
alert("Decimal numbers are not allowed for")
false
我不允许小数 .
字符:
jQuery(document).ready(function () {
jQuery(".no_decimal").keydown(function (e) {
if (e.keyCode == 190)
return false;
});
});
CoffeeScript 中的上述内容:
jQuery(document).ready ->
jQuery('.no_decimal').keydown (e) ->
if e.keyCode == 190
return false
return
return
如果您仍然坚持只检查表单提交,请使用:
if adj_value.indexOf('.') != -1
alert("Decimal numbers are not allowed for")
return false