• Really Really simple regex.
    10 replies, posted
I need a really simple regex, but I don't want to bother looking in to it for 1 thingie. it basicly needs to check if a string has 1 dot in it not more not less and if after that dot there are 1-5 random Letters not numbers.
"^\\.[a-zA-Z]{1,5}$" Couple things I'm assuming: PCRE, single line, and nothing before or after the string you are validating. My test cases: [code] .words - validates .whoop - validates word.words - fails this.is.atest - fails this.is.a.test - fails teh - fails .cakes - validates [/code]
Regex seems pretty simple
Ooh how would I let this pass ? word.words - fails and still letting this fail : this.is.atest - fails this.is.a.test - fails edit : Sorry for not being clear enough.
[QUOTE=quincy18;17773331]Ooh how would I let this pass ? word.words - fails and still letting this fail : this.is.atest - fails this.is.a.test - fails edit : Sorry for not being clear enough.[/QUOTE] Just gotta stick a [a-zA-Z]* on the front of it, like so: "^[a-zA-Z]*\\.[a-zA-Z]{1,5}$" Mind you this would still let stuff like ".words" validate, so let me know if that's not what you want.
[QUOTE=VoiDeD;17789353]"^[a-zA-Z]*\\.[a-zA-Z][b][u]{1,5}[/u][/b]$"[/QUOTE] How did I miss this? D:
Oke well I understand it now only I do not understand this : "^[a-zA-Z][b]*\[/b]\.[a-zA-Z]{1,5}$" What does this do ?
[QUOTE=quincy18;17789972]Oke well I understand it now only I do not understand this : "^[a-zA-Z][b]*\[/b]\.[a-zA-Z]{1,5}$" What does this do ?[/QUOTE] In the actual regex, that will appear as a single backslash. As you're entering it into some sort of language (C++, Lua, PHP, whatever), you must escape the backslash with another one, as backslashes are considered escape characters in many languages.
I've set up a simple script to test the regex but it isn't outputting anything :S [php] <html> <head> <title>Wassup</title> </head> <body> <form name="input" action="test.php" method="post"> validate <input type="text" name="user" /> <input type="submit" value="Submit" /> </form> </body> </html <?php if(isset($_POST['user'])) { if(preg_match("/^[a-zA-Z]*\\.[a-zA-Z]{1,5}$/",$_POST['user'])) { echo "Valid !"; } else { echo "Non Valid !"; } } ?> [/php]
</html typo And you should move it to before the end html tag anyway
stupid type :(
Sorry, you need to Log In to post a reply to this thread.