-3

I'm trying 'port' a register page from php into c# and I'm currently facing this issue:

if(ereg("^[0-9a-zA-Z]{12,12}$",$_GET["password"])) $code = ''; {

}

if(ereg("^[0-9a-zA-Z]{13,13}$",$_GET["password"])) $code = ''; {

}

if(ereg("^[0-9a-zA-Z]{14,14}$",$_GET["password"])) $code = ''; {

}

I can't understand what does it checks in the regex and what's with the character in the variable $code ( I mean , what kind of character it is so I can add the same character in c#)

user555
  • 1,564
  • 2
  • 15
  • 29
Jonnie
  • 51
  • 1
  • 5
  • 1
    You could actually paste the formatted code here, than pasting images. – Hariprasad Dec 21 '13 at 21:49
  • 1
    the regex is checking if it is an alphanumeric string of a certain length – Tim Seguine Dec 21 '13 at 21:50
  • This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged. – Krish R Dec 21 '13 at 21:51
  • 1
    in reference to the comment by @user876345 : the regex syntax looks to be compatible with preg_match – Tim Seguine Dec 21 '13 at 21:53
  • If I paste the code instead of the image the character in the $code is shown like this $code = '' , I don't know what's with that character added in the variable .. – Jonnie Dec 21 '13 at 21:53
  • @Jonnie `FF` is the control character for [form feed](http://en.wikipedia.org/wiki/Page_break) and `SO` is the [shift out](http://en.wikipedia.org/wiki/Shift_Out_and_Shift_In_characters) control character. – user555 Dec 21 '13 at 22:08
  • * See also [Open source RegexBuddy alternatives](http://stackoverflow.com/questions/89718/is-there) and [Online regex testing](http://stackoverflow.com/questions/32282/regex-testing) for some helpful tools, or [RegExp.info](http://regular-expressions.info/) for a nicer tutorial. – mario Dec 21 '13 at 23:03

1 Answers1

1

The ^ at the start of a RegEx means that the regular expression HAS to start with whatever comes next.

Everything between [ and ] are you you are matching. In your case, the number 0 to 9, and the letter a through z, both capital and lower case.

The numbers inside {} means minimum and maximum length. So your first one has the be exactly 12 characters long.

The $ at the end means that is the end of the line.

All in all, each RegEx means that it can ONLY have alpha-numeric characters, and the length is different for each.

Justin Wood
  • 9,941
  • 2
  • 33
  • 46