Not allow spaces in username

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Not allow spaces in username

Post by bruceholt » 2020-11-14 02:03

Hi all,

Is there a way to stop new users from using usernames with spaces in them?

Thanks Bruce

User avatar
zibrahim
Veteran Member
Posts: 137
Joined: 2020-01-28 18:30
Location: Malaysia

Re: Not allow spaces in username

Post by zibrahim » 2020-11-14 09:14

Hi Bruce,
You can use the following javascript code in your hooks/<tablename>-dv.js file
(replace the <tablename> with your actual tablename)

Code: Select all

// Set input to reject space. File hooks/tablename-dv.js
$j('#<fieldname>').keyup(function () {
    $j(this).val($j(this).val().replace(/\s/g, ''));
});
(don't forget to replace the <fieldname> with the corresponding fieldname)

Good luck and stay safe.
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.

User avatar
zibrahim
Veteran Member
Posts: 137
Joined: 2020-01-28 18:30
Location: Malaysia

Re: Not allow spaces in username

Post by zibrahim » 2020-11-14 10:31

Just realized that you were asking about username as if new user registration field... hmmm
Sorry for the misunderstanding.
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.

User avatar
zibrahim
Veteran Member
Posts: 137
Joined: 2020-01-28 18:30
Location: Malaysia

Re: Not allow spaces in username

Post by zibrahim » 2020-11-14 11:23

I have tried the following and it works...
I add similar code into the membership_signup.php file. (I am not sure if it will get overwritten when you regenerate the application.)
It should be around line 181 where you can see this code

Code: Select all

$j('#username').on('keyup blur', checkUser);
I put the following code above that line

Code: Select all

$j('#username').keyup(function () {
	$j(this).val($j(this).val().replace(/\s/g, ''));
});
Good luck and stay safe.
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.

User avatar
bruceholt
Veteran Member
Posts: 100
Joined: 2016-07-30 20:16
Location: Australia

Re: Not allow spaces in username

Post by bruceholt » 2020-11-14 21:31

Hi Zala, Thanks for the help. It worked perfectly.

User avatar
zibrahim
Veteran Member
Posts: 137
Joined: 2020-01-28 18:30
Location: Malaysia

Re: Not allow spaces in username

Post by zibrahim » 2020-11-15 03:42

No problem...just remember to add the code if it is overwritten when you regenerate the application.

Stay safe.
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.

Post Reply