Jump to content

Way to stop all the ASCII Characters?


crimsonmoon

Recommended Posts

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
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

[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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.