我100%新编程,这就是我想要的:
我的代码:
string message =
"Name: " + nameTextBox.Text +
"\nCard Number: " + cardNumberTextBox.Text +
"\nExpiry Date: " + expiryDateTextBox.Text +
"\nSecurity Code: " + securityCodeTextBox.Text +
"\nOrder: Pizza " + pizzaType + ", " + pizzaSize;
if (TotalToppingQuantities() > 0)
{
for (int toppingIndex = 0; toppingIndex < toppingQuantities.Length; toppingIndex++)
{
if (toppingQuantities[toppingIndex] > 0)
{
message += ", " + toppingQuantities[toppingIndex] + " x " +
toppingNames[toppingIndex];
}
}
}
message +=
"\nPickup Spot: " + pickupSpot +
"\nDelivery Time: 30 minutes";
MessageBox.Show(message);
答案 0 :(得分:2)
对于您的问题,regex
是一个很好的解决方案。
这应该对你有用
using System.Text.RegularExpressions;
//====================================
if (Regex.Match(nameTextBox.Text, "\\d").Success)
{
MessageBox.Show("(Name) must contain No numbers");
return ;
}
if (!Regex.Match(cardNumberTextBox.Text, "^\\d{16}$").Success)
{
MessageBox.Show("(Card Number) must be Limited to 16 digits and no letters");
return ;
}
if (!Regex.Match(expiryDateTextBox.Text, "^\\d{2}/\\d{2}$").Success)
{
MessageBox.Show("(Expiry Date) must be Numbers like this - 02/17 and no letters");
return ;
}
if (!Regex.Match(securityCodeTextBox.Text, "^\\d{3}$").Success)
{
MessageBox.Show("(Security Code) must be Limited to 3 numbers and no letters.");
return ;
}