Teach Yourself PHP in 10 Minutes [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Teach Yourself PHP in 10 Minutes [Electronic resources] - نسخه متنی

Chris Newman

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید






Enforcing Data Rules


You will often want to ensure not only that data is entered into required fields but that the quality of the data is good enough before proceeding. For instance, you might want to check that an email address or a phone number has the right format, using the rules developed in Lesson 8, "Regular Expressions." You could also enforce a minimum length on a field to make sure a user cannot just enter an x in each field to continue to the next page.Listing 13.1 after the required fields check to enforce suitable values for email address and telephone number:


if ($_POST["email"] &&
!ereg("^[^@]+@([a-z0-9\-]+\.)+[a-z]{2,4}$",
$_POST["email"]))
$err .= "Email address format was incorrect <br>";
if ($_POST["telephone"] &&
!ereg("^\([[:digit:]]{3}\)[[:digit:]]{3}-[[:digit:]]{4}$",
$_POST["telephone"]))
$err .= "Telephone must be in format (555)555-5555 <br>";

Because these additional rules add new messages to $err if an error is found, the rest of the script remains unchanged.


/ 126