为自定义策略添加限制,并声明可选的Azure B2C [英] Add restrictions to custom policy and make claim optional Azure B2C

查看:74
本文介绍了为自定义策略添加限制,并声明可选的Azure B2C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用LocalAccountSignUpWithLogonName自定义策略来收集用户详细信息.我添加了<OutputClaim ClaimTypeReferenceId="email" /> 到LocalAccountSignUpWithLogonName作为outputclaim.我想将电子邮件字段设为可选,但是如果用户输入电子邮件,则要启用限制.以下是我的电子邮件声明

I am trying to collect user details using LocalAccountSignUpWithLogonName custom policy.I have added <OutputClaim ClaimTypeReferenceId="email" /> to LocalAccountSignUpWithLogonName as outputclaim. I want to make the email field optional, but if user enter the email I want to enable the restrictions.Below is my email claim

<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>

但是,当我在声明中添加模式限制时,它使该字段成为必填字段.

But when I add the pattern restriction to claim, its making the field mandatory.

推荐答案

我是通过将正则表达式从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-] +)* $`.

I achieved it by changing the regular expression from RegularExpression="^[a-zA-Z0-9.+!#$%&amp;'^_{}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$" to RegularExpression="^$|^[a-zA-Z0-9.+!#$%&amp;'^_{}~-]+@[a-zA-Z0-9-]+(?:.[a-zA-Z0-9-]+)*$" `.

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

I had to prefix the expression with ^$| which accept blank/empty or the actual email.

这篇关于为自定义策略添加限制,并声明可选的Azure B2C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆