我在表单上有一个 TextEdit。其中包含网站地址文本字段、电话(美国)、电子邮件。我想从 .cs 文件中验证所有这些。请问有人可以帮助我吗?
WPF 标记:
<dxe:TextEdit x:Name="txtEmpFacebook" TabIndex="25" MaxLength="30" HorizontalAlignment="Left" Margin="606,0,0,3" VerticalAlignment="Bottom" Width="88" LostFocus="txtEmpFacebook_LostFocus"/>
<Label x:Name="lblEmpFacebookError" Content="*" Foreground="Red" HorizontalAlignment="Left" Margin="985,94,0,0" VerticalAlignment="Top" RenderTransformOrigin="13.467,-0.231" Grid.Row="1"/>
protected bool ValidateAllContactDetails()
{
bool isfocused = false;
bool isValid = true;
//Validate Contact First Name
if (string.IsNullOrEmpty(txtEmpFirstName.Text))
{
isValid = false;
lblEmpFirstNameError.Visibility = Visibility.Visible;
if (!isfocused)
{
isfocused = true;
txtEmpFirstName.Focus();
}
}
else
{
lblEmpFirstNameError.Visibility = Visibility.Hidden;
}
}
这适用于空文本并显示错误。但现在想验证现有代码中的网站 URL 格式、电话(美国)格式、电子邮件格式。任何人都可以帮助我吗?帮助赞赏!