Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6319903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:52:53+00:00 2026-05-24T15:52:53+00:00

I’m trying to validate a php register form using valid8 jquery plugin. i need

  • 0

I’m trying to validate a php register form using valid8 jquery plugin. i need to check the username available or not using php and mysql. so i check the email availability example and trying to implement the code to check the username. problem im having is with the php loop.

here is what i have right now

valid8 jquery homepage http://unwrongest.com/projects/valid8/

Register php javascript

<script type="text/javascript">
            // <![CDATA[    
            $(document).ready(function(){               

                // Set focus to first input
                $('#inputUsername').focus();

                // Custom validator (checks if password == confirm password)
                function confirmPassword(args){
                    if(args.password == args.check)
                        return {valid:true}
                    else
                        return {valid:false, message:'Passwords does not match'}
                }

                // Username is required
                $('#inputPassword, #inputUsername').valid8();

                // Confirm password must match Password
                $('#inputConfirmPassword').valid8({
                    regularExpressions: [
                        {expression: /^.+$/, errormessage: 'Required'}
                    ],
                    jsFunctions:[
                        { 'function': confirmPassword, 'values': function(){
                            return {password: $('#inputPassword').val(), check: $('#inputConfirmPassword').val()}
                        }}
                    ]
                });

                $('#inputUsername').valid8({
                    regularExpressions: [
                        {expression: /^.+$/, errormessage: 'Required'}
                    ],
                    ajaxRequests: [
                        { url: 'class/isUsernameUnique.php', loadingmessage: 'Checking availability...', errormessage:'Username is unavailable'}
                    ]
                });

                $('#inputPolicy').valid8();

                $('#inputEmail').valid8({
                    regularExpressions: [
                        {expression: /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(aero|asia|biz|cat|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel.ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|er|es|et|eu|fi|fj|fk|fm|.fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|.il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)\b$/, errormessage: 'You sure it is valid? The next step in this registration will be sent to the email you enter here.'}
                    ]
                });

                // Check if all input fields are valid
                $('#buttonSignup').click(function(){
                    alert('Are input fields valid? ' + $('input').isValid());
            });




            }); 
            // ]]>
        </script>  

isUsernameUnique.php code

<?php
    include ("db.php");

    $username = $_POST['value'];

if(!isUsernameUnique($username)){
 $json["valid"] = false;
 $json["message"] = 'username is already in use';
}
else {
 $json["valid"] = true;
}

function isUsernameUnique($username){
 // Database look-up should go here here...
 // But for the sake of this demo a random return will do
     $result = mysql_query("SELECT username FROM users WHERE username ='$username'")
     if ($result > 0);

 return rand(0, 1);
}

print json_encode($json);
    ?>

I cant seems to get the results correctly. can someone tell me how to fix this. thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T15:52:54+00:00Added an answer on May 24, 2026 at 3:52 pm
    function isUsernameUnique($username){
     // Database look-up should go here here...
     // But for the sake of this demo a random return will do
         $result = mysql_query("SELECT username FROM users WHERE username ='$username'");
         $num_rows = mysql_num_rows($result);
         if ($num_rows > 0) // userName found
            // return accordingly
    
    }
    

    $result is object or use this if condition

    if ($result) // userName found
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.