JAVA での電子メール検証に問題があります (これは初めて)、これらのエラーが発生し続け、その理由について混乱しています。私はその人の電子メールを受け取り、設定された基準を(私の教授によって)チェックしてから、テストに関する情報を入手することになっています。メールを確認すると、エラーがあればそれを表示することになっています。
エラー
N:\Programming\Java\Homework\EmailAndGrade.java:29: illegal start of expression
private static boolean validEmail(sEmail);
^
N:\Programming\Java\Homework\EmailAndGrade.java:29: illegal start of expression
private static boolean validEmail(sEmail);
^
N:\Programming\Java\Homework\EmailAndGrade.java:29: ';' expected
private static boolean validEmail(sEmail);
^
3 errors
コード
public class EmailAndGrade
{
public static void main(String[] args)
{
//Variables
String sEmail, sError, sTest;
int iTest;
char cGrade;
sEmail = JOptionPane.showInputDialog("Enter your email: ");
private static boolean validEmail(sEmail);
{
// editing to make requirements listed
// return email.matches("[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}");
return email.matches("[A-Z0-9]{7}+@[springfieldcollege]+\\.[edu]");
};
sError = "One or More Errors with the Input Email.\n" +
"Email is Empty.\n" +
"Email must be less than 30 characters.\n" +
"Must end in: @springfieldcollege.edu.\n" +
"Can only have one @.\n" +
"Must start with A through Z or a through z.\n" +
"Can not have: # $ % & ,\n ";
sTest = JOptionPane.showInptDialog("Enter Test Grade: ");
iTest = Integer.parseInt(sTest);
System.exit(0);
}
/*
void checkEmails()
{
for(String email : emailAddresses) {
if(validEmail(email)) {
// it's a good email - do something good with it
}
else {
// it's a bad email - do something... bad to it? sounds dirty...
JOptionPane.showMessageDialog(null,
sError,
"Email Error - Killian O'Brien",
JOptionPane.INFORMATION_MESSAGE);
}
}*/
}
*編集
わかりました、今私はこのコードを持っています
package com.mkyong.regex;
import javax.swing.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class EmailAndGrade
{
public static void main(String[] args)
{
//Variables
String sEmail, sError, sTest;
int iTest;
char cGrade;
sEmail = JOptionPane.showInputDialog("Enter your email: ");
sError = "One or More Errors with the Input Email.\n" +
"Email is Empty.\n" +
"Email must be less than 30 characters.\n" +
"Must end in: @springfieldcollege.edu.\n" +
"Can only have one @.\n" +
"Must start with A through Z or a through z.\n" +
"Can not have: # $ % & ,\n ";
sTest = JOptionPane.showInptDialog("Enter Test Grade: ");
iTest = Integer.parseInt(sTest);
System.exit(0);
}
public static boolean validEmail(String sEmail){
return email.matches("[A-Z0-9]{7}+@[springfieldcollege]+\\.[edu]");
}
public static void checkEmails(){
for(String sEemail : emailAddresses) {
if(validEmail(email)) {
// it's a good email - do something good with it
}
else {
// it's a bad email - do something... bad to it? sounds dirty...
JOptionPane.showMessageDialog(null,
sError,
"Email Error - Killian O'Brien",
JOptionPane.INFORMATION_MESSAGE);
}
}
}
}
そして、私は今これらを手に入れています
N:\Programming\Java\Homework\EmailAndGrade.java:37: cannot find symbol
symbol : method showInptDialog(java.lang.String)
location: class javax.swing.JOptionPane
sTest = JOptionPane.showInptDialog("Enter Test Grade: ");
^
N:\Programming\Java\Homework\EmailAndGrade.java:47: cannot find symbol
symbol : variable emailAddresses
location: class com.mkyong.regex.EmailAndGrade
for(String email : emailAddresses) {
^
N:\Programming\Java\Homework\EmailAndGrade.java:54: cannot find symbol
symbol : variable sError
location: class com.mkyong.regex.EmailAndGrade
sError,
^
N:\Programming\Java\Homework\EmailAndGrade.java:63: cannot find symbol
symbol : variable email
location: class com.mkyong.regex.EmailAndGrade
return email.matches("[A-Z0-9]{7}+@[springfieldcollege]+\\.[edu]");
^
4 errors
これを入力していると、宣言されていない変数がたくさんあることに気付きました。それは正しいでしょうか?