简体   繁体   English

如何检查Java中的文本字段中是否输入了某个值

[英]How to check whether a certain value is entered in a textfield in Java

Does anyone know how to check whether someone entered something in a textfield in java which isn't allowed (depending on my requirements)?有谁知道如何检查是否有人在 java 的文本字段中输入了不允许的内容(取决于我的要求)?

It is my intention that no special characters can be entered, but now it's possible to enter "=true" (according to the function, it then satisfies, because it returns a true).我的意图是不能输入特殊字符,但现在可以输入“=true”(根据 function,它满足,因为它返回 true)。 I've written a function to check whether the username is correct or not.我写了一个 function 来检查用户名是否正确。

I have already solved it.我已经解决了。 I made a string variable that retrieves the entered text and add a trim() and toLowerCase() function.我创建了一个字符串变量来检索输入的文本并添加一个 trim() 和 toLowerCase() function。 Then I check if the entered value is equal to certain values and if it contains some special chars.然后我检查输入的值是否等于某些值以及它是否包含一些特殊字符。 For me it's works well now.对我来说,它现在运作良好。

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

相关问题 如何检查用户输入的字符串在Java中是否是某个字母? - How to check if a string entered by a user is a certain letter in Java? 如何检查输入的出生日期是否有效 - How to check whether a Birth Date entered is valid 如何使用Java中的hasNextInt来检查输入的值是否为integer? - How to use hasNextInt in Java to check if the entered value is integer or not? 我如何让我的Java程序等到在文本字段中输入值 - How do i make my java program wait until there is entered a value into the textfield 我可以检查 List 是否包含一个对象,该对象具有在 java 中具有特定值的字段吗? - Can I check whether a List contains an object that has fields with a certain value in java? 如何在Java / Android中检查字符串值是否属于UUID? - How to check a whether string value belongs to UUID or not in java/android? 如何在Java中插入值之前检查数组列表中是否已存在值? - How to check whether a value is already in an arraylist before inserting it in Java? Java-如何根据输入的文本长度更改textField的尺寸? - Java - How to make a textField dimensions change based on the length of text entered? 如何检查是否输入了值,如果没有输入则重新提示它们 - How to check if value is entered, and if nothing is entered reprompt them 如何在Java中检查输入的输入是否为整数? - How to check that the entered input is an integer or not in java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM