the success message is not displaying after form submission, still it's displaying error message "Please enter a valid mobile number." it should display Success message.

<?php
function filterMobileno($field){
    // Sanitize mobile number
    $field = filter_var($field, FILTER_SANITIZE_NUMBER_INT);

    // Validate mobile number
    if(filter_var($field, FILTER_VALIDATE_INT)){
        return $field;
    }else{
        return FALSE;
    }
}   
// Define variables and initialize with empty values
$mobilenoErr = "";
$mobile_no = ""; 

// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){

    // Validate mobile number
    if(empty($_POST["mobile_no"])){
        $mobilenoErr = 'Please enter your mobile number.';
    }else{
        $mobile_no = filterMobileno($_POST["mobile_no"]);
        if($mobile_no == FALSE){
            $mobilenoErr = 'Please enter a valid mobile number.';
        }
        elseif(!preg_match("/^\d{10}$/", $mobile_no) ) { 
        $mobilenoErr = 'Please enter 10 digit Mobile Number.';
    }  
    } 


   if(empty($mobilenoErr)){
      echo 'success'; 
  }
} 
   ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Missed Call Alert</title>

    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style type="text/css">
        .error{ color: red; }
        .success{ color: green; }
    </style>
  </head>
  <div class="navbar navbar-default navbar-fixed-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
<a class="navbar-brand" href="http://manage.smspanel.in">SMSPanel.in</a>
        </div>

        <div class="navbar-collapse collapse">
          <ul class="nav navbar-nav navbar-right">
            <li><a href="#"><?php echo $_SESSION['sess_username'];?></a></li>
            <li><a href="templates.php">Templates</a></li>
            <li><a href="compose_message.php">Compose Message</a></li>
            <li><a href="logout.php">Logout</a></li>
          </ul>
        </div>
      </div>
    </div>

  <div class="container">
      <div class="info">
         <h2 class="bg-primary">Missed Call Control Panel</h2>

          <div class="col-md-6 col-md-offset-3">
                    <h4></span>Register New Mobile Number<span class="glyphicon glyphicon-user"></h4><br/>
                            <div class="block-margin-top">


                              <form action="compose_message.php" method="POST" class="form-signin col-md-8 col-md-offset-2" role="form">  

                                  <input type="text" name="mobile_no" class="form-control" placeholder="Mobile Number" value="<?php echo $mobile_no; ?>"><br/>
                                  <span class="error"><?php echo $mobilenoErr; ?></span>

                                  <!-- <input type="password" name="password" class="form-control" placeholder="Password" required><br/>-->
                                  <button class="btn btn-lg btn-primary btn-block" type="submit">Submit</button>
                             </form>
                           </div>
            </div>

      </div>


    </div>   

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
    </body>
</html>
Member Avatar for diafol

Just a thought. Telephone numbers are not integers. They usually have leading zeroes. ALso some may have leading + (for intl. numbers). They may contain brackets too.

Here's a link to one of my fave sites for regex:

http://regexlib.com/Search.aspx?k=mobile&c=-1&m=-1&ps=20

It has loads of user-supplied examples. My personal opinion on this would be - forget it - heh heh. You may just want to allow the following: + ( ) \d . Maybe dashes too?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.