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.

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;
        return FALSE;
// Define variables and initialize with empty values
$mobilenoErr = "";
$mobile_no = ""; 

// Processing form data when form is submitted

    // Validate mobile number
        $mobilenoErr = 'Please enter your mobile number.';
        $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.';

      echo 'success'; 
<!DOCTYPE html>
<html lang="en">
    <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=""></script>
      <script src=""></script>
    <style type="text/css">
        .error{ color: red; }
        .success{ color: green; }
  <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>
<a class="navbar-brand" href=""></a>

        <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>

  <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>



    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src=""></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
Member Avatar

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:

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, learning, and sharing knowledge.