0
我想验证java文本区域中的选项卡,因为输入保存在按标签拆分的文本文件中。如果我键入标签,它将不会读取下一个输入。我试过了,例如:String.matches(“\ t”),但它不起作用。 谢谢。如何验证jText区域中的选项卡?
这里是我的代码:
String Title = textfield.getText();
String Description = textarea.getText();
if (Description.matches("\t"))
{
JOptionPane.showMessageDialog(this, "Tab is not allowed");
}
else
{
try
{
File f = new File("Data.txt");
try (BufferedWriter writer = new BufferedWriter (new FileWriter(f,true)))
{
writer.write(Title+"\t"+Description+System.lineSeparator());
}
}
catch(IOException e)
{
}
}
它工作!非常感谢!你能解释这些代码吗? – Pepper
该点匹配任何字符,*表示“多次前面的表达(点)”。所以这个正则表达式的意思是:“任意数量的字符(零个或多个),后跟一个制表符,后跟任意数量的字符”。 –
很好的解释。谢谢! – Pepper