当输入有效详细信息时,当第一个名称大于15时,它仍然显示设计中内容的无效代码然后我想要错误,我也不希望重复名字或姓氏。所以当我输入正确的详细信息我的程序仍显示错误我希望它在插入正确的详细信息时显示提交。
public partial class MainWindow : Window
{
public DateTime? currentDate;
public string previousDate;
public string previousFirstName = "";
public string previousSurname = "";
public string previousEmailAddress = "";
int previousTimeIndex = 12;
public MainWindow()
{
InitializeComponent();
}
private void DatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
{
var datePicker = sender as DatePicker;
currentDate = datePicker.SelectedDate;
}
private void button_Click_1(object sender, RoutedEventArgs e)
{
// validation checks
string Title = comboBox.Text;
string FirstName = First_Name.Text;
string Surname = Sur_name.Text;
string EmailAddress = Email_Address.Text;
int TimeSelector = comboBox2.SelectedIndex;
// valid or not switch
bool validInput = true;
// Title can only be one of these in my design its a drop down box so
// when the title is not one of them I want to see a error saying invalid
if (Title != "Mr" && Title != "Mrs" && Title != "Miss" && Title != "Other")
{
validInput = false;
}
if (FirstName.Length > 15) // first name
{
validInput = false;
}
if (Surname.Length > 15) // surname
{
validInput = false;
}
if (!EmailAddress.Contains("@") || !EmailAddress.Contains(".co") || !EmailAddress.Contains(".co.uk") ||
!EmailAddress.Contains(".com")) // email address
{
validInput = false;
}
if (currentDate.ToString().Equals(previousDate)) // current date
{
validInput = false;
}
// Time selector
if (TimeSelector == previousTimeIndex)
{
validInput = false;
}
// Submit button code
if (validInput == true)
{
submit.Content = "Submitted";
// I also dont wanna be able to enter the same name again
//if the same name is to be used twice it has to in a different time.
previousDate = currentDate.ToString();
previousFirstName = FirstName;
previousSurname = Surname;
previousEmailAddress = EmailAddress;
}
else
{
submit.Content = "Invalid Input(s)";
}
}
} .............................................................................
答案 0 :(得分:0)
问题似乎在验证EmailAddress的行中:
public static void main(String... args) throws Exception {
Demo myDemo = new EnhancedDemo();
System.out.println(myDemo.b());
//output: -> Enhanced A
}
要使此检查返回有效结果,您的EmailAddress必须包含if (!EmailAddress.Contains("@") || !EmailAddress.Contains(".co") || !EmailAddress.Contains(".co.uk") || !EmailAddress.Contains(".com")) // email address
以及@
,.co
和.co.uk
之一。你可能想要这样的东西
.com