Regex Validation for email field on sign in page

Manish Aggarwal 36 Reputation points
2022-09-16T10:46:06.827+00:00

Hi - We are working on Azure AD B2C implementation, where in we need to validate the signin email entered by customer using a regex validation.

We do the email Verification using claims, but also need to enforce regex validation (Pattern) on client side.

Microsoft Security Microsoft Entra Microsoft Entra External ID
{count} votes

2 answers

Sort by: Most helpful
  1. Nasreen Akter 10,811 Reputation points Volunteer Moderator
    2022-09-16T12:29:45.163+00:00

  2. Shweta Mathur 30,296 Reputation points Microsoft Employee Moderator
    2022-09-19T05:29:47.223+00:00

    Hi @Manish Aggarwal ,

    Thanks for reaching out.

    I understand you are trying to validate the email entered by customer using a regex validation in B2C custom policy.

    You can use pattern element with Regular Expression in order to validate the email id enter by customer. You can customized the regular expression based on your requirement.

    <ClaimType Id="email">  
     <DisplayName>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>  
     </ClaimType>  
    

    Hope this will help.

    Thanks,
    Shweta

    -----------------------------------------------

    Please remember to "Accept Answer" if answer helped you.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.