/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Check if fits.

I cannot figure out regular expressions. Examples would help.

How would I make it check if $variable is in “1.23” “12.3” or “12” format.
Also how would you check if $variable is “filename.gif|png|bmp|jpg or directory/filename.gif|png|bmp|jpg.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@jasonahouleDec 03.2007 — There are lots of different was to do it. You don't have to use regular expressions if you don't want to. The first example you could use strpos() to find the location of the decimal. The second one you could use explode() to get the extension and then a switch statement to test for a value.

Anyway, my point is regex is not your only option.
Copy linkTweet thisAlerts:
@Pixel-ArtistauthorDec 03.2007 — There are lots of different was to do it. You don't have to use regular expressions if you don't want to. The first example you could use strpos() to find the location of the decimal. The second one you could use explode() to get the extension and then a switch statement to test for a value.

Anyway, my point is regex is not your only option.[/QUOTE]


Well I really don't care where the decimal point or even if it does have a decimal point just want to to be numbers with or without a decimal point.
Copy linkTweet thisAlerts:
@jasonahouleDec 03.2007 — well, if you just want to know if it is a number than use is_numeric()
×

Success!

Help @Pixel-Artist 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 5.16,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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