Apply custom client side validation on Age field on AD B2C

Ronnie Kapoor 96 Reputation points
2020-12-17T13:06:06.697+00:00

I'm trying to configure a B2C tenant using custom policies.

In the sign up page, I added a custom claim to ask the user about his/her birth date. If the user provides a date which make him/her an under age (+18), I would like to display a verification failed message (like the one you can set by using predicates) and prevent the user to be able to sign up by the create button being disabled.

I want this validation to be client side as well as server side. How can i achieve this ?

Microsoft Entra External ID
Microsoft Entra External ID
A modern identity solution for securing access to customer, citizen and partner-facing apps and services. It is the converged platform of Azure AD External Identities B2B and B2C. Replaces Azure Active Directory External Identities.
2,874 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. 2020-12-17T17:47:05.07+00:00

    Hello, from within the custom policy (server side) you can use transformations such as GetCurrentDateTime, DateTimeComparison to compare time passed between the later and the former and AssertBooleanClaimIsEqualToValue to validate the later output. You will need to find a way to determine how many leap years have passed to properly set the DateTimeComparison timeSpanInSeconds input param. Or you might just add a REST technical profile as a validation one that calls an API you develop that does the heavy lifting.

    Client side you can use vanilla JS or jQuery to validate the the DOM element value created for the claim. The element will use the claim name as it's id. EG:

       <input id="phoneNumber" />  
    

    Please let me know if you need more help. If the answer was helpful to you, please accept it and, optionally, provide feedback so that other members in the community can benefit from it.

    0 comments No comments

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.