/    Sign up×
Community /Pin to ProfileBookmark

Validating number of characters from form field

Hello,

I have the following script:

[code=php]
if (empty($_POST[‘company_name’])) {
$message[] = ‘Please enter a company name’;
$cn = FALSE;
} else {
$cn = escape_data(strip_tags(stripslashes(trim($_POST[‘company_name’]))));
}
[/code]

I was wondering how I go about adding a Reg Exp so that the ‘company_name’ has to be greater than 3 characters? I thought this’d be quite easy to do.

Thanks for any help with this.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 28.2007 — I would just use strlen(), unless perhaps you also want to simultaneously validate other attributes of the value.
[code=php]
if(strlen($_POST['company_name']) < 4)
{
// too short
}
[/code]
Copy linkTweet thisAlerts:
@invisionauthorOct 28.2007 — Aaaah, that's great NogDog - many thanks!
Copy linkTweet thisAlerts:
@pcthugOct 28.2007 — To save the little overhead associated with a function call;

[code=php]
if (!isset($_POST['company_name'][3]))
{
// too short
}
[/code]
×

Success!

Help @invision 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.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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

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