简体   繁体   English

如何验证文本字段中的用户输入以将其与变量进行比较?

[英]How to verify the user input in a textfield to compare it with a variable?

I want to verify the user input (number) in a textfield that if it's bigger than 9 or not. 我想验证textfield中的用户输入(数字)是否大于9 Note that the number from 1 to 9 . 请注意,数字从19 if it's bigger than 9 I want to show a jOptionPane some code i have traied: 如果它大于9我想向jOptionPane显示一些我已经讲过的代码:

else
        if(jTextField1.contains()){ // want to compare it if it's bigger than 9 or not

            jOptionPane1.showMessageDialog(this,"Please enter the number of the tab"); // wich means from 1 to 9
        }

So how to do that with java? 那么如何用Java做到这一点呢? Thanks in advance :) 提前致谢 :)

You can directly do it with help of js using jQuery just give id to our text field and add a script tag with the following code : 您可以直接在jQuery的帮助下使用jQuery做到这一点,只需将id赋予我们的文本字段并使用以下代码添加脚本标签即可:

num = $("#yourId").val();
if(num>9){
alert("your message");
}

or any thing else you want to achieve 或您想要实现的任何其他目的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM