Jump to content

[SOLVED] ereg()


Northern Flame

Recommended Posts

I've never used ereg() before,

but am now trying it out.

I want to only allow letters, numbers, and

underscores in my usernames but

the following script doesn't work:

 

<?php
$username = $_POST['username'];
$ereg = ereg("([a-zA-Z0-9_])", $username);
if ($ereg) {
echo $username;
} else {
    echo "Invalid format: $username";
}
?>

 

if I am to input ';;;;;'

it returns "Invalid format: ;;;;;"

but if I enter 'test;'

it returns 'test;' which means

it accepted it, how can I

fix this?

 

Thanks for reading!

Link to comment
https://forums.phpfreaks.com/topic/83920-solved-ereg/
Share on other sites

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.