The problem: I'm making updates to a Community which uses a login flow and self registration for users. I've noticed that it is possible for users to register without providing any input for First Name, which is a problem and needs to be fixed.

My question: How can I create validation to ensure that users always provide both a first & last name when doing self registration? Can I use Javascript on a self register page? I would like the solution to be client-side validation on the same page -- I don't want to have the validation re-direct the user to an error page, it must be on the same page.

Please keep in mind that I'd like to avoid customising any apex controllers as much as possible. However I realise that I might have to in this case.

Thanks in advance!


Yes it is Possible, you have to define 2 attributes in the lightning component, a Boolean and a String.

<aura:attribute name="showError" type="Boolean" default="false" access="private"/>
<aura:attribute name="errorMessage" type="String" access="private"/>

then, all what you have to do, is to check the value of the wanted fields when registering.

    if ($A.util.isEmpty(YOUR_VAR)) {
       component.set("v.showError", true);
       component.set("v.errorMessage", "XYZ");
  • I would also advise adding a validation rule on server side, as JS can be easily hacked and modified. – Pranay Jaiswal Apr 30 '18 at 10:54
  • @Mo Hamada -- I presume that code snippet should go inside the controller? I did not have any luck getting this to work. The standard variable in the SelfRegister component is "firstname", so I used that in the place of YOUR_VAR, but nothing is happening. Can you give me more context about where to place the code perhaps? – JustinF May 10 '18 at 5:22
  • @JustinF You have to put it in ghe JavaScript controller, in the save method, so when ever the user leave the firstname (in your case) empty, and try to save his Input, the variable will be checked. Did you get what i mean? – Mo Hamada May 10 '18 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.