SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 30 of 30
  1. #26
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,676
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by billy_111 View Post
    Whilst i am doing this, i was wondering how the password checking would work?
    Do not limit the types of password characters someone can use. That's only inviting weak security if you do that.
    When it comes to passwords, the greater the types of characters can be used, the better.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  2. #27
    SitePoint Enthusiast
    Join Date
    Jun 2011
    Location
    Dartmouth, MA, USA
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I agree, checking whether the e-mail exists via AJAX is a good thing to do. The more you can validate for the user up front before submitting the form, the better. Just be sure to do all the same checks after the form is submitted, too.

    I was thinking you'd want to do the password match check in JavaScript (you could do most of these checks in JavaScript, except for checking that the e-mail address hasn't been taken already and any other similar tasks) but PHP via AJAX works too. If you ever do use JavaScript for client-side validation though, whatever server-side script the form is being submitted to must also make the same validations since JavaScript can be bypassed.

    Anyway, if you want to do the check server-side, the PHP code you wrote will work, except you need to change the calls to $_POST to $_GET since your AJAX calls use GET as their type. In validateIt, you'll also need to check if it's a password you're validating, in which case you need to pass the other password so that they can be checked to see if they match. You'll have to tweak your PHP code to allow for this on the server-side so that it can handle taking both passwords. And instead of calling GET directly in your function, you could just handle that up front by extracting the two password values right away and then passing them to the validateCheckPassword function, making it more reusable.

  3. #28
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello again

    I want to extend the validation on the "alphanum" method to accept spaces as well. The reason is that when a user enters their Postcode it can have spaces, so if i enter this:

    OL45 1DF
    It will return as invalid as there is a space. So i thought of changing the method to this:

    PHP Code:
    function validateAlphanum($value) {
        if(
    preg_match("[^A-Za-z0-9\s]"$value)) {
                echo 
    "true";
        } else {
                echo 
    "invalid";
        }

    But that didn't work it still returned as "invalid"?

    Any ideas what i can do for this?

    Many thanks,
    Software Engineer ASP, ASP.NET, VB, PHP

    Kind regards
    Billy

  4. #29
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,676
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by billy_111 View Post
    I want to extend the validation on the "alphanum" method to accept spaces as well. The reason is that when a user enters their Postcode it can have spaces
    Please do not change the behaviour of the validateAlphaNum function, because it will have unexpected consequences when other parts of the code use it, and spaces really are not allowed in those other parts.

    What you can do instead, is to not use alphanum for the postcode, but to use a special "postcode" one, from which you can remove spaces from the value that is sent to the validateAlphaNum function. That's the simplest solution.

    Code php:
    case 'postcode': 
        validateAlphanum(str_replace(' ', '', $value)); 
        break;

    Alternatively you can create a completely different function that performs the precise post code checks that you need.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #30
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Brilliant, thats worked for me

    Also, if i want to enforce a minimum length for a number such as the phone number, i was trying to use this:

    ^\d{5}$
    But that didn't work. Reason i am doing this is that a person can enter a phone number of a single digit and that is not correct.

    Can you see what i am doing wrong above?

    Many thanks,

    EDIT - I got it to work with this: /^[0-9]{6,}$/
    Software Engineer ASP, ASP.NET, VB, PHP

    Kind regards
    Billy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •