这是我的表单,其中包含邮件和电话两个条目以及发送按钮
<StackLayout HorizontalOptions="FillAndExpand" Orientation="Vertical" Grid.Row="0" Margin="0,5,0,5">
<Label>
<Label.FormattedText>
<FormattedString>
<Span FontSize="16" Text="Phone" TextColor="#07987f"></Span>
<Span FontSize="16" Text=": " TextColor="#07987f"></Span>
</FormattedString>
</Label.FormattedText>
</Label>
<Entry x:Name="entryPhone" Placeholder="Phone" Text="{Binding Phone}">
<Entry.Behaviors>
<xct:TextValidationBehavior x:Name="phoneValidationRule" Flags="ValidateOnUnfocusing" RegexPattern="^07[0-9]{7}$"/>
</Entry.Behaviors>
</Entry>
</StackLayout>
<StackLayout HorizontalOptions="FillAndExpand" Orientation="Vertical" Grid.Row="1" Margin="0,5,0,5">
<Label>
<Label.FormattedText>
<FormattedString>
<Span FontSize="16" Text="E-mail" TextColor="#07987f"></Span>
<Span FontSize="16" Text=": " TextColor="#07987f"></Span>
</FormattedString>
</Label.FormattedText>
</Label>
<Entry x:Name="entryEmail" Placeholder="Email" Text="{Binding Email}">
<Entry.Behaviors>
<xct:EmailValidationBehavior x:Name="emailValidationRule" Flags="ValidateOnUnfocusing"/>
</Entry.Behaviors>
</Entry>
</StackLayout>
<Button Text="SEND" Clicked="ValidationFormForRegistraitonClicked" TextColor="#07987f" BackgroundColor="#eeeeee" Margin="0,10,0,10"></Button>
<StackLayout>
<Label IsVisible="{Binding IsValidMail}" Text="ENTER VALID EMAIL"></Label>
<Label IsVisible="{Binding IsValidPhone}" Text="ENTER VALID PHONE"></Label>
</StackLayout>
这是我的验证功能:
private void ValidationFormForRegistraitonClicked(object sender, EventArgs e)
{
if (!emailValidationRule.IsValid)
viewModel.IsValidMail = true;
else
viewModel.IsValidMail = false;
if (!phoneValidationRule.IsValid)
viewModel.IsValidPhone = true;
else
viewModel.IsValidPhone = false;
}
当条目为空且有效声明且错误时,我遇到问题。我有一个简单的要求。如果输入有效的地址和有效的电话通过它。如何解决这个问题?