CoderFunda
  • Home
  • About us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • About us
  • Home
  • Php
  • HTML
  • CSS
  • JavaScript
    • JavaScript
    • Jquery
    • JqueryUI
    • Stock
  • SQL
  • Vue.Js
  • Python
  • Wordpress
  • C++
    • C++
    • C
  • Laravel
    • Laravel
      • Overview
      • Namespaces
      • Middleware
      • Routing
      • Configuration
      • Application Structure
      • Installation
    • Overview
  • DBMS
    • DBMS
      • PL/SQL
      • SQLite
      • MongoDB
      • Cassandra
      • MySQL
      • Oracle
      • CouchDB
      • Neo4j
      • DB2
      • Quiz
    • Overview
  • Entertainment
    • TV Series Update
    • Movie Review
    • Movie Review
  • More
    • Vue. Js
    • Php Question
    • Php Interview Question
    • Laravel Interview Question
    • SQL Interview Question
    • IAS Interview Question
    • PCS Interview Question
    • Technology
    • Other
Showing posts with label Validation. Show all posts
Showing posts with label Validation. Show all posts

20 November, 2018

Form Validation-PHP Form in Hindi

 Programing Coderfunda     November 20, 2018     php, Validation     No comments   

जब HTML Form को create किया जाता है तब उसे validate भी किया जाता है | Validate करने का मतलब यही है कि जो भी User इस form को fill कर रहा है वो सही information डाले |
अगर User से valid information send करनी हो तो कुछ चीजों पर ध्यान रखना पड़ता है |
  • Name : Name के सिर्फ letters और whitespace valid होंगे |
  • UserName : UserName में सिर्फ letters और numbers ही valid होंगे |
  • Email : Email में letters या nummbers उसके बाद @ symbol उसके बाद letters उसके बाद . (dot) और आखिरी में letters
  • URL : URL valid होगा |
  • Mobile Number : सिर्फ Number valid और length 10 digit तक होगी |
  • Gender : Radio तो एक select होगा |
  • Comment : Comment required नहीं है |

Name Validation

Source Code :
1234567891011121314151617181920<?php
$nameerror ="";
if(isset($_POST['submit'])){
if (empty($_POST["name"])) {
$nameerror = "Name is required";
}else{
$name = $_POST["name"];
if(!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameerror = "Only Letters and White Space allowed";
}}}
?>
<form action="" method="post">
Name : <input type="text" name="name" ><?php echo $nameerror; ?>

<input type="submit" name="submit" />

<?php
if(isset($_POST["submit"])){
echo "Name : ".$_POST["name"];
}
?>
Output :
Click to Name : Form Validation

UserName Validation

Source Code :
1234567891011121314151617181920<?php
$usernameerror ="";
if(isset($_POST['submit'])){
if (empty($_POST["username"])) {
$usernameerror = "UserName is required";
}else{
$username = $_POST["username"];
if(!preg_match("/^[a-zA-Z0-9]+$/", $username)) {
$usernameerror = "Only Letters and Numbers allowed";
}}}
?>
<form action="" method="post">
UserName : <input type="text" name="username" ><?php echo $usernameerror; ?><br />
<input type="submit" name="submit" />
</form>
<?php
if(isset($_POST["submit"])){
echo "UserName : ".$_POST["username"];
}
?>
Output :
Click to UserName : Form Validation

Email Validation

Source Code :
1234567891011121314151617181920<?php
$emailerror ="";
if(isset($_POST['submit'])){
if (empty($_POST["email"])) {
$emailerror = "Email is required";
}else{
$email = $_POST["email"];
if(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) {
$emailerror = "Invalid Email Format";
}}}
?>
<form action="" method="post">
Email : <input type="text" name="email" ><?php echo $emailerror; ?><br />
<input type="submit" name="submit" />
</form>
<?php
if(isset($_POST["submit"])){
echo "Email : ".$_POST["email"];
}
?>
Output :
Click to Email : Form Validation

URL Validation

Source Code :
1234567891011121314151617181920<?php
$urlerror ="";
if(isset($_POST['submit'])){
if (empty($_POST["URL"])) {
$urlerror = "URL is required";
}else{
$url = $_POST["URL"];
if(!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $url)) {
$urlerror = "Invalid URL Format";
}}}
?>
<form action="" method="post">
URL : <input type="text" name="URL" ><?php echo $urlerror; ?><br />
<input type="submit" name="submit" />
</form>
<?php
if(isset($_POST["submit"])){
echo "URL : ".$_POST["URL"];
}
?>
Output :
Click to URL : Form Validation

Mobile Number Validation

Source Code :
1234567891011121314151617181920<?php
$mobnoerror ="";
if(isset($_POST['submit'])){
if (empty($_POST["mobno"])) {
$mobnoerror = "Mobile Number is required";
}else{
$mobno = $_POST["mobno"];
if(!preg_match("/^\d{10}$/", $mobno)) {
$mobnoerror = "Only Numbers with 10 Digits required";
}}}
?>
<form action="" method="post">
Mobile No. : <input type="text" name="mobno" ><?php echo $mobnoerror; ?><br />
<input type="submit" name="submit" />
</form>
<?php
if(isset($_POST["submit"])){
echo "Mobile No. : ".$_POST["mobno"];
}
?>
Output :
Click to Mobile No. : Form Validation


Gender Required

Source Code :
12345678910111213141516<?php
$gendererror ="";
if(isset($_POST['submit'])){
if(empty($_POST["gender"])) {
$gendererror = " Gender is required";
}}
?>
<form action="" method="post">
<input class="radio" name="gender" type="radio" value="female">Female
<input class="radio" name="gender" type="radio" value="male">Male <?php echo $gendererror; ?><br />
<input type="submit" name="submit" />
</form>
<?php
if(isset($_POST["gender"]))
echo $_POST["gender"];
?>
Output :
Click to Gender : Form Validation

Comment No Validation

Source Code :
1234567891011121314151617<?php
$comment ="";
if (isset($_POST["submit"])){
if (empty($_POST["comment"])) {
$comment = "";
}}
?>
<form action="" method="post">
Comment :
<textarea cols="50" name="comment" rows="5">
</textarea><br />
<input type="submit" name="submit" />
</form>
<?php
if(isset($_POST["comment"]))
echo $_POST["comment"];
?>
Output :
Click to Comment : No Form Validation

Full Example For Form Validation

Source Code :
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109<?php
$nameerror ="";
$usernameerror="";
$emailerror ="";
$mobnoerror = "";
$gendererror ="";
$urlerror ="";
$comment="";

if(isset($_POST['submit'])){
if(empty($_POST["name"])){
$nameerror = "Name is required";
}else{
$name = $_POST["name"];
if(!preg_match("/^[a-zA-Z ]*$/",$name)){
$nameerror = "Only Letters and White Space allowed";
}}
if (empty($_POST["username"])){
$usernameerror = "UserName is required";
}else{
$username = $_POST["username"];
if(!preg_match("/^[a-zA-Z0-9]+$/", $username)){
$usernameerror = "Only Letters and Numbers allowed";
}}
if (empty($_POST["email"])){
$emailerror = "Email is required";
}else{
$email = $_POST["email"];
if(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)){
$emailerror = "Invalid Email Format";
}}
if (empty($_POST["URL"])){
$urlerror = "URL is required";
}else{
$url = $_POST["URL"];
if(!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $url)){
$urlerror = "Invalid URL Format";
}}
if (empty($_POST["mobno"])){
$mobnoerror = "Mobile Number is required";
}else{
$mobno = $_POST["mobno"];
if(!preg_match("/^\d{10}$/", $mobno)){
$mobnoerror = "Only Numbers with 10 Digits required";
}}
if(empty($_POST["gender"])){
$gendererror = " Gender is required";
}
if (empty($_POST["comment"])){
$comment = "";
}
}
?>


<!DOCTYPE html>
<html>
<head>
<title>Form Validation</title>
<style type="text/css">
.error{
color:#F00;
}
</style>
</head>
<body>
<h2>Form Validation</h2>
<form action="" method="post">
<span class="error">* required field.</span><br />
Name:
<input class="input" name="name" type="text" value="">
<span class="error">* <?php echo $nameerror;?></span><br />
UserName :
<input class="input" name="username" type="text" value="">
<span class="error">* <?php echo $usernameerror;?></span><br />
E-mail:
<input class="input" name="email" type="text" value="">
<span class="error">* <?php echo $emailerror;?></span><br />
URL :
<input class="input" name="URL" type="text" value="">
<span class="error">* <?php echo $urlerror;?></span><br />
Mobile Number :
<input class="input" name="mobno" type="text" value="">
<span class="error">* <?php echo $mobnoerror;?></span><br />
Gender:
<input type="radio" name="gender" value="female">Female
<input type="radio" name="gender" value="male">Male
<span class="error">*<?php echo $gendererror; ?></span><br />
Comment:
<textarea cols="40" name="comment" rows="5">
</textarea><br />
<input class="submit" name="submit" type="submit" value="Submit">
</form>
<br />

<h2>Information</h2>
<?php
if(isset($_POST["submit"])){
echo "Name : ".$_POST["name"]."<br />";
echo "UserName : ".$_POST["username"]."<br />";
echo "Email : ".$_POST["email"]."<br />";
echo "URL : ".$_POST["URL"]."<br />";
echo "Mobile No : ".$_POST["mobno"]."<br />";
echo "Gender : ".$_POST["gender"]."<br />";
echo "Comment : ".$_POST["comment"];
}
?>
</body>
</html>
Output :
Click to Form Validation


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Form Validation-PHP Form in Hindi

 Programing Coderfunda     November 20, 2018     php, Validation     No comments   

जब HTML Form को create किया जाता है तब उसे validate भी किया जाता है | Validate करने का मतलब यही है कि जो भी User इस form को fill कर रहा है वो सही information डाले |
अगर User से valid information send करनी हो तो कुछ चीजों पर ध्यान रखना पड़ता है |
  • Name : Name के सिर्फ letters और whitespace valid होंगे |
  • UserName : UserName में सिर्फ letters और numbers ही valid होंगे |
  • Email : Email में letters या nummbers उसके बाद @ symbol उसके बाद letters उसके बाद . (dot) और आखिरी में letters
  • URL : URL valid होगा |
  • Mobile Number : सिर्फ Number valid और length 10 digit तक होगी |
  • Gender : Radio तो एक select होगा |
  • Comment : Comment required नहीं है |

Name Validation

Source Code :
1234567891011121314151617181920<?php
$nameerror ="";
if(isset($_POST['submit'])){
 if (empty($_POST["name"])) {
$nameerror = "Name is required";
}else{
$name = $_POST["name"];
if(!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameerror = "Only Letters and White Space allowed";
}}}
?>
<form action="" method="post">
Name : <input type="text" name="name" ><?php echo $nameerror; ?>

<input type="submit" name="submit" />

<?php
if(isset($_POST["submit"])){
echo "Name : ".$_POST["name"]; 
}
?>
Output :
Click to Name : Form Validation

UserName Validation

Source Code :
1234567891011121314151617181920<?php
$usernameerror ="";
if(isset($_POST['submit'])){
 if (empty($_POST["username"])) {
$usernameerror = "UserName is required";
}else{
$username = $_POST["username"];
if(!preg_match("/^[a-zA-Z0-9]+$/", $username)) {
$usernameerror = "Only Letters and Numbers allowed";
}}}
?>
<form action="" method="post">
UserName : <input type="text" name="username" ><?php echo $usernameerror; ?><br />
<input type="submit" name="submit" />
</form>
<?php
if(isset($_POST["submit"])){
echo "UserName : ".$_POST["username"]; 
}
?>
Output :
Click to UserName : Form Validation

Email Validation

Source Code :
1234567891011121314151617181920<?php
$emailerror ="";
if(isset($_POST['submit'])){
 if (empty($_POST["email"])) {
$emailerror = "Email is required";
}else{
$email = $_POST["email"];
if(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) {
$emailerror = "Invalid Email Format";
}}}
?>
<form action="" method="post">
Email : <input type="text" name="email" ><?php echo $emailerror; ?><br />
<input type="submit" name="submit" />
</form>
<?php
if(isset($_POST["submit"])){
echo "Email : ".$_POST["email"]; 
}
?>
Output :
Click to Email : Form Validation

URL Validation

Source Code :
1234567891011121314151617181920<?php
$urlerror ="";
if(isset($_POST['submit'])){
 if (empty($_POST["URL"])) {
$urlerror = "URL is required";
}else{
$url = $_POST["URL"];
if(!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $url)) {
$urlerror = "Invalid URL Format";
}}}
?>
<form action="" method="post">
URL : <input type="text" name="URL" ><?php echo $urlerror; ?><br />
<input type="submit" name="submit" />
</form>
<?php
if(isset($_POST["submit"])){
echo "URL : ".$_POST["URL"]; 
}
?>
Output :
Click to URL : Form Validation

Mobile Number Validation

Source Code :
1234567891011121314151617181920<?php
$mobnoerror ="";
if(isset($_POST['submit'])){
 if (empty($_POST["mobno"])) {
$mobnoerror = "Mobile Number is required";
}else{
$mobno = $_POST["mobno"];
if(!preg_match("/^\d{10}$/", $mobno)) {
$mobnoerror = "Only Numbers with 10 Digits required";
}}}
?>
<form action="" method="post">
Mobile No. : <input type="text" name="mobno" ><?php echo $mobnoerror; ?><br />
<input type="submit" name="submit" />
</form>
<?php
if(isset($_POST["submit"])){
echo "Mobile No. : ".$_POST["mobno"]; 
}
?>
Output :
Click to Mobile No. : Form Validation


Gender Required

Source Code :
12345678910111213141516<?php
$gendererror ="";
if(isset($_POST['submit'])){
if(empty($_POST["gender"])) {
$gendererror = " Gender is required";
}}
?>
<form action="" method="post">
<input class="radio" name="gender" type="radio" value="female">Female
<input class="radio" name="gender" type="radio" value="male">Male <?php echo $gendererror; ?><br />
<input type="submit" name="submit" />
</form>
<?php 
if(isset($_POST["gender"]))
echo $_POST["gender"]; 
?>
Output :
Click to Gender : Form Validation

Comment No Validation

Source Code :
1234567891011121314151617<?php
$comment ="";
if (isset($_POST["submit"])){
if (empty($_POST["comment"])) {
$comment = "";
}}
?>
<form action="" method="post">
Comment :
<textarea cols="50" name="comment" rows="5">
</textarea><br />
<input type="submit" name="submit" />
</form>
<?php 
if(isset($_POST["comment"]))
echo $_POST["comment"]; 
?>
Output :
Click to Comment : No Form Validation

Full Example For Form Validation

Source Code :
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109<?php
$nameerror ="";
$usernameerror="";
$emailerror ="";
$mobnoerror = "";
$gendererror ="";
$urlerror ="";
$comment="";

if(isset($_POST['submit'])){
if(empty($_POST["name"])){
$nameerror = "Name is required";
}else{
$name = $_POST["name"];
if(!preg_match("/^[a-zA-Z ]*$/",$name)){
$nameerror = "Only Letters and White Space allowed";
}}
if (empty($_POST["username"])){
$usernameerror = "UserName is required";
}else{
$username = $_POST["username"];
if(!preg_match("/^[a-zA-Z0-9]+$/", $username)){
$usernameerror = "Only Letters and Numbers allowed";
}}
if (empty($_POST["email"])){
$emailerror = "Email is required";
}else{
$email = $_POST["email"];
if(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)){
$emailerror = "Invalid Email Format";
}}
if (empty($_POST["URL"])){
$urlerror = "URL is required";
}else{
$url = $_POST["URL"];
if(!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $url)){
$urlerror = "Invalid URL Format";
}}
if (empty($_POST["mobno"])){
$mobnoerror = "Mobile Number is required";
}else{
$mobno = $_POST["mobno"];
if(!preg_match("/^\d{10}$/", $mobno)){
$mobnoerror = "Only Numbers with 10 Digits required";
}}
if(empty($_POST["gender"])){
$gendererror = " Gender is required";
}
if (empty($_POST["comment"])){
$comment = "";
}
}
?>


<!DOCTYPE html>
<html>
<head>
<title>Form Validation</title>
<style type="text/css">
.error{
 color:#F00;
}
</style>
</head>
<body>
<h2>Form Validation</h2>
<form action="" method="post">
<span class="error">* required field.</span><br />
Name:
<input class="input" name="name" type="text" value="">
<span class="error">* <?php echo $nameerror;?></span><br />
UserName :
<input class="input" name="username" type="text" value="">
<span class="error">* <?php echo $usernameerror;?></span><br />
E-mail:
<input class="input" name="email" type="text" value="">
<span class="error">* <?php echo $emailerror;?></span><br />
URL :
<input class="input" name="URL" type="text" value="">
<span class="error">* <?php echo $urlerror;?></span><br />
Mobile Number :
<input class="input" name="mobno" type="text" value="">
<span class="error">* <?php echo $mobnoerror;?></span><br />
Gender:
<input type="radio" name="gender" value="female">Female
<input type="radio" name="gender" value="male">Male
<span class="error">*<?php echo $gendererror; ?></span><br />
Comment:
<textarea cols="40" name="comment" rows="5">
</textarea><br />
<input class="submit" name="submit" type="submit" value="Submit">
</form>
<br />

<h2>Information</h2>
<?php
if(isset($_POST["submit"])){
echo "Name : ".$_POST["name"]."<br />";
echo "UserName : ".$_POST["username"]."<br />";
echo "Email : ".$_POST["email"]."<br />";
echo "URL : ".$_POST["URL"]."<br />";
echo "Mobile No : ".$_POST["mobno"]."<br />";
echo "Gender : ".$_POST["gender"]."<br />"; 
echo "Comment : ".$_POST["comment"];
}
?>
</body>
</html>
Output :
Click to Form Validation


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Older Posts Home

Meta

Popular Posts

  • JqueryUI - Show
    JqueryUI - Show, JqueryUI,  This chapter will discuss the show() method, which is one of the methods used to manage jQueryUI visual effe...
  • Crawl and Index Your Website with Laravel Site Search
      Laravel Site Search   is a package by Spatie to create a full-text search index by crawling your site. You can think of it as a private Go...
  • WordPress Table
    WordPress Table WordPress table is an easy way to show the data in the table format. In the past, we had used the HTML code or table plugin ...
  • Python exec() Function
    Python exec() Function The python  exec()  function is used for the dynamic execution of Python program which can either be a string or obje...
  • CodeIgniter - Adding JS & CSS
    Adding JavaScript and CSS (Cascading Style Sheet) file in CodeIgniter is very simple. You have to create JS and CSS folder in root directo...

Categories

  • Ajax (26)
  • Bootstrap (30)
  • DBMS (42)
  • HTML (12)
  • HTML5 (45)
  • JavaScript (10)
  • Jquery (34)
  • Jquery UI (2)
  • JqueryUI (32)
  • Laravel (1017)
  • Laravel Tutorials (23)
  • Laravel-Question (6)
  • Magento (9)
  • Magento 2 (95)
  • MariaDB (1)
  • MySql Tutorial (2)
  • PHP-Interview-Questions (3)
  • Php Question (13)
  • Python (36)
  • RDBMS (13)
  • SQL Tutorial (79)
  • Vue.js Tutorial (69)
  • Wordpress (150)
  • Wordpress Theme (3)
  • codeigniter (108)
  • oops (4)
  • php (853)

Social Media Links

  • Follow on Twitter
  • Like on Facebook
  • Subscribe on Youtube
  • Follow on Instagram

Pages

  • Home
  • Contact Us
  • Privacy Policy
  • About us

Blog Archive

  • July (4)
  • September (100)
  • August (50)
  • July (56)
  • June (46)
  • May (59)
  • April (50)
  • March (60)
  • February (42)
  • January (53)
  • December (58)
  • November (61)
  • October (39)
  • September (36)
  • August (36)
  • July (34)
  • June (34)
  • May (36)
  • April (29)
  • March (82)
  • February (1)
  • January (8)
  • December (14)
  • November (41)
  • October (13)
  • September (5)
  • August (48)
  • July (9)
  • June (6)
  • May (119)
  • April (259)
  • March (122)
  • February (368)
  • January (33)
  • October (2)
  • July (11)
  • June (29)
  • May (25)
  • April (168)
  • March (93)
  • February (60)
  • January (28)
  • December (195)
  • November (24)
  • October (40)
  • September (55)
  • August (6)
  • July (48)
  • May (2)
  • January (2)
  • July (6)
  • June (6)
  • February (17)
  • January (69)
  • December (122)
  • November (56)
  • October (92)
  • September (76)
  • August (6)

Loading...

Laravel News

Loading...

Copyright © CoderFunda | Powered by Blogger
Design by Coderfunda | Blogger Theme by Coderfunda | Distributed By Coderfunda