Jump to content

Way to stop all the ASCII Characters?


crimsonmoon

Recommended Posts

The [color=red]|[/color] are the delimeters
the [color=red]^[/color] matches start of line
the [color=red]+[/color] matches one or more of the previous characters/classes (in this case classes)
the [color=red]$[/color] matches end of line

Rich
A note that's very important when using regular expressions is the following quantifiers:

[color=red]*[/color] means 'Zero or more'
[color=red]?[/color] means 'Zero or one'
[color=red]+[/color] means 'One or more'

And the reason that Obsidian has added the [color=green]+[/color] at the end of the character class [color=green][a-z0-9][/color] is to indicate that there must be some data entered, had he have put the following:

|^[a-z0-9][b]*[/b]$|i

Note the * instead of +

Then an empty string would be considered as valid.

Rich
[quote author=HuggieBear link=topic=105611.msg421957#msg421957 date=1156518884]
Obsidian,

You need to remove the additional 'http://' in the 'RegEx' link in your signature.  Just tried to get there  :)

Rich
[/quote]

thanks, rich... signature tends to get messed up on SMF for some reason.
[quote author=scottybwoy link=topic=105611.msg421983#msg421983 date=1156522306]
Cheers, so if I do :
[code]
<?php

$customer = preg_match('|^[a-z]+$i', $_POST['CUSTOMER']);
$customer = strtoupper($customer);
$cust = substr($customer, 0, 2);

?>
[/code]

I will get the first three letters entered in the string capitalised. Yeah?
[/quote]

well, with that, you're not actually [b]doing[/b] anything with the preg_match(). also, you're missing your closing delimiter. you'll need to do something like this:
[code]
<?php
if (preg_match('|^[a-z]+$|i', $_POST['CUSTOMER']);
  // valid match
  $customer = strtoupper($_POST['CUSTOMER']);
  $cust = substr($customer, 0, 2);
}

?>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.