/    Sign up×
Community /Pin to ProfileBookmark

problem with regular expression

[B]
hi ifinish from my web site but iwant add filter for forms iwant players use numbers

iuse this code but not work good:

$pattern = ‘/^[0-9]$/’;
if(!preg_match($pattern,$input1){
echo “not numbers”;
}else{
echo “numbers”;
}

any one can tell me whats wrong itried before use filters from w3school but ithink its not work with php4
[/B]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@bionoidDec 22.2011 — You didn't specify how you wanted your range handled properly. I added a [B]+[/B], so you will need 1 or more numbers in $input1.

But if you want zero or more numbers then change it to a [B]*[/B] (depending if a blank input is also acceptable).

[code=php]$pattern = '/^[0-9]+$/';
if (preg_match($pattern, $input1)) {
echo 'numbers';
} else {
echo 'not numbers';
}[/code]


Alternatively, your pattern could have been:

[code=php]$pattern = '/^d+$/';[/code]
Copy linkTweet thisAlerts:
@rtkwarauthorApr 08.2012 — $tagpattern = '/^[a-zA-Z0-9]{6,16}+$/';

iwant allow member leave space in field ,how?
Copy linkTweet thisAlerts:
@WolfShadeApr 08.2012 — $tagpattern = '/^[ a-z0-9]{6,16}+$/i'; will allow letters, numbers, and spaces (plural). By adding the [B]i[/B] to the end, you make it case insensitive so you can remove the A-Z.
×

Success!

Help @rtkwar spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...