Hi, i'm currently making a account system for my gamemode. I have made an email-validation-regular-expression, but it just won't work. I made it for php first, and then coded it for the garrysmod regular-expressions system. It works fine in php, but not in garrysmod. What did i do wrong?
lua-Code:
[lua]
-- The Php regex: ^.+@.+\.\w{2,3}(\.\w{2,3})?$
local str = "mail@mail.co.uk";
if(string.match(str, "^.+@.+%.%a{2,3}(%.%a{2,3}?)?$"))then
Msg("it works!")
else
Msg("Oh crap")
end
[/lua]
No errors, just pops up with the "Oh crap" message in the console.
Lua doesn't support the perl pattern syntax.
I know, but what is wrong with the regular expression i made in the lua code? It doesn't work.
Maybe there are a few syntax differences? I'm not really used to these. :smile:
Here is the page on regular expressions on the Garry's Mod wiki
[url=http://wiki.garrysmod.com/?search=Patterns][I]Patterns[/I] [img]http://wiki.garrysmod.com/favicon.ico[/img][/url]
[editline]1[/editline]
You probably don't need that but maybe you let something slip through. :v:
Try this pattern, let me see how n matches is done with Lua patterns, but I'm sure it isn't done with {}.
[lua]^[%w%p]+@[%w%p]+[.][%w%p][%w%p][%w%p]?$[/lua]
I made a simplified version of the regular-expression, and found out that i had to use "*" instead of "?", and that i couldn't use "()" the same way as in php.
Here is the code i ended up with, if anybody is interested.
[lua]
local str = "mail@mail.co.uk";
if(string.match(str, "^.+@.+%.%a%a%a*%.*%a*%a*%a*"))then
Msg("it works!")
else
Msg("Oh crap")
end
[\lua]
EDIT:Thanks for the pattern Overv. It worked :)
Sorry, you need to Log In to post a reply to this thread.