[Skip to main content](#vessel-content)

#   Regex for username on registration

##

- **[RAYFormation](/forum/user/77087-rayformation "View RAYFormation's Profile")**
- [![RAYFormation's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/77087-rayformation "View RAYFormation's Profile") Topic Author
- [ Offline](/forum/user/77087-rayformation)

Less More

- Posts: 6
- Thank you received: 0
-
-

3 years 4 months ago [\#352393](#352393) by [RAYFormation](/forum/user/77087-rayformation "View RAYFormation's Profile")  *[Regex for username on registration](/forum/27-checkout/906535-regex-for-username-on-registration#352393 "-- HikaShop version -- : 4.7.3 -- Joomla version -- : 4.3.2 -- PHP version -- : 8.1 -- Browser(s) name and version -- : Google Chrome  Hi,  I want to put a username Regex on registration. Our Website is connected with Moodle and people buy courses through Hikashop.  When a customer register himself, he can put the username he wants which is quite inconvenient as Moodle is case sensitive and refere to that username.  Can you tell me on which file should I put my Regex please ?  Thanks,")* was created by *[RAYFormation](/forum/user/77087-rayformation "View RAYFormation's Profile")*

-- HikaShop version -- : 4.7.3
-- Joomla version -- : 4.3.2
-- PHP version -- : 8.1
-- Browser(s) name and version -- : Google Chrome

Hi,

I want to put a username Regex on registration. Our Website is connected with Moodle and people buy courses through Hikashop.

When a customer register himself, he can put the username he wants which is quite inconvenient as Moodle is case sensitive and refere to that username.

Can you tell me on which file should I put my Regex please ?

Thanks,

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0LzkwNjUzNS1yZWdleC1mb3ItdXNlcm5hbWUtb24tcmVnaXN0cmF0aW9uP3RtcGw9bWFya2Rvd24=) or [Create an account](/register) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86324
- Thank you received: 14286
-
-

3 years 4 months ago [\#352396](#352396) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Regex for username on registration](/forum/27-checkout/906535-regex-for-username-on-registration#352396 "-- HikaShop version -- : 4.7.3 -- Joomla version -- : 4.3.2 -- PHP version -- : 8.1 -- Browser(s) name and version -- : Google Chrome  Hi,  I want to put a username Regex on registration. Our Website is connected with Moodle and people buy courses through Hikashop.  When a customer register himself, he can put the username he wants which is quite inconvenient as Moodle is case sensitive and refere to that username.  Can you tell me on which file should I put my Regex please ?  Thanks,")*

Hi,

Modifying directly a core file of HikaShop or Joomla is not what I would recommend.
There are two ways I would recommend doing it:
- you could develop a small Joomla plugin of the group "user" and implement the event onUserBeforeSave :
[ docs.joomla.org/Plugin/Events/User#onUserBeforeSave](https://docs.joomla.org/Plugin/Events/User#onUserBeforeSave)
That way, it works not only with HikaShop's registration form, but Joomla's and most extensions out there which need to have their own registration form. Also, since you're doing it as a plugin, you won't have to modify a core file each time you update Joomla or HikaShop, and it would work even with future versions of Joomla / HikaShop (until Joomla decides to break the plugin system but I hope it never happens)
- you could also do a view override of the registration form view. For HikaShop, you can easily find which view file you need to change :
[ www.hikashop.com/support/documentation/1...-display.html#layout](https://www.hikashop.com/support/documentation/153-customize-the-display.html#layout)
In it, you could add a javascript script to monitor what is being written in the username input field. Here is a tutorial on input field validation in javascript:
[ dev.to/dailydevtips1/vanilla-javascript-email-validation-21b3](https://dev.to/dailydevtips1/vanilla-javascript-email-validation-21b3)
Since you would do this as a view override, you won't have issues with updates for a while. However, this means you won't get the modifications we add in that view file in the future (for new features, or compatibility with future versions of Joomla), it's on the browser side of things, so bots or attackers can bypass the check, and it would only apply to the registration form in HikaShop, leaving the Joomla registration form page open with the same issue unless you also do an override for it.

So as you can see, I recommend the plugin approach. It's a bit more work if you're not familiar with how to create a plugin (but once you know how, it's nothing difficult), but in all other aspects, I think it's better.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0LzkwNjUzNS1yZWdleC1mb3ItdXNlcm5hbWUtb24tcmVnaXN0cmF0aW9uP3RtcGw9bWFya2Rvd24=) or [Create an account](/register) to join the conversation.

- **[RAYFormation](/forum/user/77087-rayformation "View RAYFormation's Profile")**
- [![RAYFormation's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/77087-rayformation "View RAYFormation's Profile") Topic Author
- [ Offline](/forum/user/77087-rayformation)

Less More

- Posts: 6
- Thank you received: 0
-
-

3 years 4 months ago [\#352568](#352568) by [RAYFormation](/forum/user/77087-rayformation "View RAYFormation's Profile")  Replied by *[RAYFormation](/forum/user/77087-rayformation "View RAYFormation's Profile")* on topic *[Regex for username on registration](/forum/27-checkout/906535-regex-for-username-on-registration#352568 "-- HikaShop version -- : 4.7.3 -- Joomla version -- : 4.3.2 -- PHP version -- : 8.1 -- Browser(s) name and version -- : Google Chrome  Hi,  I want to put a username Regex on registration. Our Website is connected with Moodle and people buy courses through Hikashop.  When a customer register himself, he can put the username he wants which is quite inconvenient as Moodle is case sensitive and refere to that username.  Can you tell me on which file should I put my Regex please ?  Thanks,")*

Hi Nicolas,

Thanks for you answer.

I did a plugin to check that the username respect my needs.

Here is a link if someone need it : [ github.com/Bwerpophile/Joomla\_Restrictusername\_plugin](https://github.com/Bwerpophile/Joomla_Restrictusername_plugin)

I'm facing a problem regarding the javascrypt side of the question.

When I try to get the value of the field, it doesn't seems to be store inside the DOM.

Do you have any idea of a work around or where can I get what is input in the field ?

Thanks again for your time,

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0LzkwNjUzNS1yZWdleC1mb3ItdXNlcm5hbWUtb24tcmVnaXN0cmF0aW9uP3RtcGw9bWFya2Rvd24=) or [Create an account](/register) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86324
- Thank you received: 14286
-
-

3 years 4 months ago [\#352569](#352569) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Regex for username on registration](/forum/27-checkout/906535-regex-for-username-on-registration#352569 "-- HikaShop version -- : 4.7.3 -- Joomla version -- : 4.3.2 -- PHP version -- : 8.1 -- Browser(s) name and version -- : Google Chrome  Hi,  I want to put a username Regex on registration. Our Website is connected with Moodle and people buy courses through Hikashop.  When a customer register himself, he can put the username he wants which is quite inconvenient as Moodle is case sensitive and refere to that username.  Can you tell me on which file should I put my Regex please ?  Thanks,")*

Hi,

What JS code are you using ?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0LzkwNjUzNS1yZWdleC1mb3ItdXNlcm5hbWUtb24tcmVnaXN0cmF0aW9uP3RtcGw9bWFya2Rvd24=) or [Create an account](/register) to join the conversation.

- **[RAYFormation](/forum/user/77087-rayformation "View RAYFormation's Profile")**
- [![RAYFormation's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/77087-rayformation "View RAYFormation's Profile") Topic Author
- [ Offline](/forum/user/77087-rayformation)

Less More

- Posts: 6
- Thank you received: 0
-
-

3 years 4 months ago -  3 years 4 months ago [\#352676](#352676) by [RAYFormation](/forum/user/77087-rayformation "View RAYFormation's Profile")  Replied by *[RAYFormation](/forum/user/77087-rayformation "View RAYFormation's Profile")* on topic *[Regex for username on registration](/forum/27-checkout/906535-regex-for-username-on-registration#352676 "-- HikaShop version -- : 4.7.3 -- Joomla version -- : 4.3.2 -- PHP version -- : 8.1 -- Browser(s) name and version -- : Google Chrome  Hi,  I want to put a username Regex on registration. Our Website is connected with Moodle and people buy courses through Hikashop.  When a customer register himself, he can put the username he wants which is quite inconvenient as Moodle is case sensitive and refere to that username.  Can you tell me on which file should I put my Regex please ?  Thanks,")*

Hi,

Vanilla JS. I tried with this : Code:

&lt;script type="text/javascript"&gt; document.addEventListener('DOMContentLoaded', function() { var emailField = document.getElementById('register_email'); var usernameField = document.getElementById('register_username'); if (emailField &amp;&amp; usernameField) { usernameField.addEventListener('input', function() { var email = emailField.value; var username = usernameField.value; if (email !== username) { usernameField.setCustomValidity('Username must match the email address.'); } else { usernameField.setCustomValidity(''); } }); } });

Last edit: 3 years 4 months ago by [nicolas](/forum/user/63-nicolas "View nicolas's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0LzkwNjUzNS1yZWdleC1mb3ItdXNlcm5hbWUtb24tcmVnaXN0cmF0aW9uP3RtcGw9bWFya2Rvd24=) or [Create an account](/register) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86324
- Thank you received: 14286
-
-

3 years 4 months ago [\#352682](#352682) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Regex for username on registration](/forum/27-checkout/906535-regex-for-username-on-registration#352682 "-- HikaShop version -- : 4.7.3 -- Joomla version -- : 4.3.2 -- PHP version -- : 8.1 -- Browser(s) name and version -- : Google Chrome  Hi,  I want to put a username Regex on registration. Our Website is connected with Moodle and people buy courses through Hikashop.  When a customer register himself, he can put the username he wants which is quite inconvenient as Moodle is case sensitive and refere to that username.  Can you tell me on which file should I put my Regex please ?  Thanks,")*

Hi,

Try to add the code Code:

var emailField = document.getElementById('register_email'); var usernameField = document.getElementById('register_username');

inside the event handler.

Note also that if your goal is for your users to have the same username and email address, why not simply set the "registration" setting of the HikaShop configuration to "simplified registration with password". That way, it will remove the username field, and the system will automatically use the email address as username.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0LzkwNjUzNS1yZWdleC1mb3ItdXNlcm5hbWUtb24tcmVnaXN0cmF0aW9uP3RtcGw9bWFya2Rvd24=) or [Create an account](/register) to join the conversation.

- **[RAYFormation](/forum/user/77087-rayformation "View RAYFormation's Profile")**
- [![RAYFormation's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/77087-rayformation "View RAYFormation's Profile") Topic Author
- [ Offline](/forum/user/77087-rayformation)

Less More

- Posts: 6
- Thank you received: 0
-
-

3 years 4 months ago [\#352714](#352714) by [RAYFormation](/forum/user/77087-rayformation "View RAYFormation's Profile")  Replied by *[RAYFormation](/forum/user/77087-rayformation "View RAYFormation's Profile")* on topic *[Regex for username on registration](/forum/27-checkout/906535-regex-for-username-on-registration#352714 "-- HikaShop version -- : 4.7.3 -- Joomla version -- : 4.3.2 -- PHP version -- : 8.1 -- Browser(s) name and version -- : Google Chrome  Hi,  I want to put a username Regex on registration. Our Website is connected with Moodle and people buy courses through Hikashop.  When a customer register himself, he can put the username he wants which is quite inconvenient as Moodle is case sensitive and refere to that username.  Can you tell me on which file should I put my Regex please ?  Thanks,")*

Hi,

All right, that sort everything.

I did not know that Hikashop was putting the email as username on simple registration.

I did that in the end.

Thanks,

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0LzkwNjUzNS1yZWdleC1mb3ItdXNlcm5hbWUtb24tcmVnaXN0cmF0aW9uP3RtcGw9bWFya2Rvd24=) or [Create an account](/register) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.086 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
