PHP ctype Functions | ctype Functions In PHP In Hindi
PHP Program to check whether number is Palindrome or not | PHP Find Palindrome Number
PHP com port communication In Hindi | Write on com port in PHP
Selection Sort in PHP With Example | How does selection sort work in PHP ?
PHP Form validation | Validate User Input Data In PHP In Hindi
Snowflake Virtual warehouses In Hindi | Create warehouse In Snowflake In Hindi
Tasks In Snowflake | What is Task In Snowflake
If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
Modern web application में किसी भी type के data को store या process करने से पहले data को validate किया जाता है , ताकि applications को secure और reliable बनाया जा सके।
PHP by default कुछ functionalities provide की हैं जिनकी help से हम external data को validate कर सकें।
●●●
filter_var()
function का use अलग - अलग specified filter के according data को filter और sanitize करने के लिए।
filter_var(data, flag, options);
data
: filter / sanitize करने के लिए pass value । यह required value है।
flag
: filter_var()
function में कई अलग अलग तरह के flags किये जाते हैं। यह भी required value है।
options
: यह भी optional field है। यहां आप एक या एक से ज्यादा flags/options pass कर सकते हैं , अगर आप advance level के filtering करना चाहते हैं।
नीचे example में email को filter किया गया है।
function validate_email($email) {
// first remove all illegal characters.
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
// Validate e-mail
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo("$email is a valid email");
}
else {
echo("$email is not a valid email");
}
}
validate_email("johndoe@gmail");
validate_email("johndoe#gmail.com");
validate_email("johndoe@gmail.com");
Output
johndoe@gmail is not a valid email johndoe#gmail.com is not a valid email johndoe@gmail.com is a valid email
●●●
filter_var()
के साथ ctype_digit()
function का use करके आप mobile number easily validate कर सकते हैं।
function validate_mobile($mobile) {
// first remove all illegal characters.
$email = filter_var($mobile, FILTER_SANITIZE_DIGIT);
if (ctype_digit($mobile) && strlen($mobile)==10) {
echo("$mobile is valid mobileno");
}
else {
echo("$mobile is not valid mobileno");
}
}
validate_mobile("7889677889");
validate_mobile("788967788");
validate_mobile("78896778KL");
Output
7889677889 is valid mobileno 788967788 is not valid mobileno 78896778KL is not valid mobileno
Learn more about ctype functions in PHP
इसी तरह से filter_var()
function के साथ कई प्रकार से data को validate कर सकते हैं , इसके लिए कई तरह के filter flags की available हैं।
●●●
I hope , PHP में filter_var()
function क्या है और क्या काम करता है आप अच्छे से समझ गए होंगे ।
Loading ...
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook