/    Sign up×
Community /Pin to ProfileBookmark

Validation — cant get it to work correctly

I cant get these two pieces of my validation to work…

if I have an IP of 192.168.1.1 — it fails… it only passes if I have 192.168.111.100 — a full IP ….. it needs to accept number like 10.1.1.1 etc…

[CODE]#
# IP address
#
$field = $ipaddress;
$field_name = “<b>IP Address</b>”;
if( (!$field)
|| strlen($field) < 8 || strlen($field) > 15
|| !preg_match(“/[0-9]{3}+[.]{1}+[0-9]{3}+[.]{1}+[0-9]{3}+[.]{1}+[0-9]{3}/”, $field, $matches )
)
{
$error_string .= $field_name . ” cannot be empty and can only contain numbers 0-9 and periods (ex. 192.168.101.102).<br />”;
}
[/CODE]

this one just always fails…

[CODE]#
# check phone
#
$field = $Phone;
$field_name = “<b>Phone Number</b>”;
if( (!$field)
|| strlen($field) == 12 || strlen($field) > 12
|| !preg_match(“/[0-9]{3}+[-]{1}+[0-9]{3}+[-]{1}+[0-9]{4}/”, $field, $matches )
)
{
$error_string .= $field_name . ” must be in 10 digit format (ex. 811-555-1212).<br />”;
}[/CODE]

can anyone help me out..

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@so_is_thisNov 30.2006 — For each of these: {3}

specify as follows: {1,3}
×

Success!

Help @Humper 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.18,
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,
)...