I need a function on client side

Started by Mohamed Boubekri, Mar 25, 2021, 09:51 PM

Previous topic - Next topic

Mohamed Boubekri

I have a function in client side that like a condition:-
if (after.edit.Text.len() > 0)

if (after.edit.Text.len() < 19)
As you see these condition, now the idea is i want to add a new condition that Meaning, the name must contain a symbol
I have take a function from mta sa forum just to you understand what i meaning:-
characterName = string.gsub(tostring(characterName), " ", "_")As i said before, i want to add a new condition that Meaning, the name must contain a symbol, and the symbole must be _ like in previous code, i want the name like John_smith, Mohamed_L'oujdi, i want if the player not typing the symbole return false.
| What now ? | Not yet ! |
Morrocan:- [ 🇲🇦 ].

Kelvin Garcia Mendoza

#1
Quote from: We3da on Mar 25, 2021, 09:51 PMi want the name like John_smith, Mohamed_L'oujdi, i want if the player not typing the symbole return false.

Considering what you said here, I made the following function that will only return true if the nickname format is A_B (where A and B are letters from a/A to z/Z). It's expected to return false otherwise.
function IsNicknameValid( nickname )
{
 return regexp( @"^\a+_\a+$" ).match( nickname );
}

So, this
IsNicknameValid( "abc" );
IsNicknameValid( "_abc" );
IsNicknameValid( "abc_" );
IsNicknameValid( "abc__def" ); // Note the double underscore.
IsNicknameValid( "abc_def_ghi" );
IsNicknameValid( "_" );
IsNicknameValid( "________" );

// No numbers or special caracters allowed.
IsNicknameValid( "Hack_Man69" );
IsNicknameValid( "Mohamed_VC-MP" );
will return false, whereas
IsNicknameValid( "abc_def" );
IsNicknameValid( "Hack_Man" );
IsNicknameValid( "Mohamed_VCMP" );
will return true.

I used Squirrel's regexp() function for this example. You can learn more about this function by clicking here.

Mohamed Boubekri

I saw the site yesterday, But didn't know how to use it. Anyway your function working great thanks.
| What now ? | Not yet ! |
Morrocan:- [ 🇲🇦 ].