IfStringValidEmail
#1

Hello Everyone,

Ive been trying to make a function with a string perimter but i failed everytime.It should work like When a string is input into the function , it checks that 'The string entered is in valid format of an email address or not'

Ex: sampscripting@something.com

So it should check for these things:
1. The @ symbol ofcourse.
2. String 1 before the @ Symbol.
3. String 2 after the @ sybmol.
4. The Dot . after this string 2.
5. String 3 should be there after the dot symbol.

Question: Why i can not script/code it?
Answer: I suck at strings. Bunked every lecture of it in the past semester. I regret it now.

If anyone can please help me , that would be so kind and really great.

Thank you
Ballu Miaa
Reply
#2

This is a perfect job for regular expressions, luckily Fro1sha made an plugin for it.

https://sampforum.blast.hk/showthread.php?tid=247893

Theres even a copy paste email validator for you to use, good luck.
Reply
#3

Damn thanks a lot to you. Rep+6 Added.

How exactly do i need to use this?

I am writing the steps correct me if im wrong:
1. Download the plugin and install it into my server files properly.
2. Include it in my game mode.
3. Copy this nearly on the top.?
pawn Код:
#define IsValidEmail(%1) \
    regex_match(%1, "[a-zA-Z0-9_\\.]+@([a-zA-Z0-9\\-]+\\.)+[a-zA-Z]{2,4}")
4. Add this function in the game mode , compile?
pawn Код:
stock IsValidTextEx(const string[])
{
    static
        RegEx:rText
    ;
   
    if ( !rText )
    {      
        rText = regex_build("[ а-яА-Яa-zA-Z0-9_,!\\.\\?\\-\\+\\(\\)]+");
    }
   
    return regex_match_exid(string, rText);
}
5. Example of Usage of this function?
Reply
#4

You can use it different ways, the simples would be to just add the define to the top of your GM and doing like if(IsValidEmail(string)) { }

No need to add that function, you can though make a function for it, that function uses regex_build which is a bit faster as it only makes the regex statement once during runtime. However for this email check that'll probably only be used once for each player it'll do fine with the regular way.
Reply
#5

Quote:
Originally Posted by playbox12
Посмотреть сообщение
You can use it different ways, the simples would be to just add the define to the top of your GM and doing like if(IsValidEmail(string)) { }

No need to add that function, you can though make a function for it, that function uses regex_build which is a bit faster as it only makes the regex statement once during runtime. However for this email check that'll probably only be used once for each player it'll do fine with the regular way.
So which one should i use? Or make a custom function?

pawn Код:
#define IsValidEmail(%1) \
    regex_match(%1, "[a-zA-Z0-9_\\.]+@([a-zA-Z0-9\\-]+\\.)+[a-zA-Z]{2,4}")

// OR SHALL I USE THIS?

stock IsValidTextEx(const string[])
{
    static
        RegEx:rText
    ;
   
    if ( !rText )
    {      
        rText = regex_build("[ а-яА-Яa-zA-Z0-9_,!\\.\\?\\-\\+\\(\\)]+");
    }
   
    return regex_match_exid(string, rText);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)