Page 1 of 1

Not allow spaces in username

Posted: 2020-11-14 02:03
by bruceholt
Hi all,

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

Thanks Bruce

Re: Not allow spaces in username

Posted: 2020-11-14 09:14
by zibrahim
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.

Re: Not allow spaces in username

Posted: 2020-11-14 10:31
by zibrahim
Just realized that you were asking about username as if new user registration field... hmmm
Sorry for the misunderstanding.

Re: Not allow spaces in username

Posted: 2020-11-14 11:23
by zibrahim
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.

Re: Not allow spaces in username

Posted: 2020-11-14 21:31
by bruceholt
Hi Zala, Thanks for the help. It worked perfectly.

Re: Not allow spaces in username

Posted: 2020-11-15 03:42
by zibrahim
No problem...just remember to add the code if it is overwritten when you regenerate the application.

Stay safe.