为自定义策略添加限制,并声明可选的Azure B2C

时间:2018-08-28 00:44:52

标签: azure-ad-b2c identity-experience-framework

我正在尝试使用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.+!#$%&amp;'^_{}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$" HelpText="Please enter a valid email address." />
</Restriction>

但是当我将样式限制添加到声明时,它使该字段成为必填字段。

1 个答案:

答案 0 :(得分:1)

我通过将正则表达式从RegularExpression="^[a-zA-Z0-9.+!#$%&amp;'^_{}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$"更改为RegularExpression="^$|^[a-zA-Z0-9.+!#$%&amp;'^_ {}〜-] + @ [a-zA-Z0-9-] +(?:。[a-zA- Z0-9-] +)* $“`。

我必须在表达式前加上^$|,以接受空白/空或实际的电子邮件。