我正在尝试使用LocalAccountSignUpWithLogonName自定义策略收集用户详细信息。我已将<OutputClaim ClaimTypeReferenceId="email" />
添加到LocalAccountSignUpWithLogonName作为outputclaim。我想让电子邮件字段可选,但如果用户输入电子邮件我想启用限制。这是我的电子邮件声明
<ClaimType Id="email">
<DisplayName>Your Email Address</DisplayName>
<DataType>string</DataType>
<DefaultPartnerClaimTypes>
<Protocol Name="OpenIdConnect" PartnerClaimType="email" />
</DefaultPartnerClaimTypes>
<UserHelpText>Email address that can be used to contact you.</UserHelpText>
<UserInputType>TextBox</UserInputType>
<Restriction>
<Pattern RegularExpression="^[a-zA-Z0-9.+!#$%&'^_{}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$" HelpText="Please enter a valid email address." />
</Restriction>
但是当我添加模式限制来声明时,它使该字段成为必需的。
我通过将正则表达式从RegularExpression="^[a-zA-Z0-9.+!#$%&'^_{}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$"
更改为RegularExpression="^$|^[a-zA-Z0-9.+!#$%&'^_
{}〜 - ] + @ [a-zA-Z0-9 - ] +(?:。[a-zA-Z0-9 - ] +)* $“来实现它。 。
我必须在表达式前加上^$|
,它接受空白/空或实际的电子邮件。