What is JotForm?
JotForm is a free online form builder which helps you create online forms without writing a single line of code. No sign-up required.

At JotForm, we want to make sure that you’re getting the online form builder help that you need. Our friendly customer support team is available 24/7.

We believe that if one user has a question, there could be more users who may have the same question. This is why many of our support forum threads are public and available to be searched and viewed. If you’d like help immediately, feel free to search for a similar question, or submit your question or concern.


  • Profile Image

    Custom PHP script code to validate Swedish SSN number.

    Asked by BiggerPenis on January 18, 2015 at 06:39 PM

    Hello everyone!

    Does anyone know if it is possible to add a "validating function" to a specific field i created? I'm creating a order form where I need to validate the customers social security number but a Swedish one.

    I made a field with input mask ######-#### ten digits and need this field to be validated.

    Merci- Tack - Thank you for helping!!!

    <?php
     $pnr get_magic_quotes_gpc() ? $_POST['personnr'] : mysql_real_escape_string($_POST['personnr']);
     
    if (checkPnr($pnr)) {
       echo 'RÄTT!';
    } else {
       echo 'FEL!';
    }
     
    function checkPnr($pnr) {
        if ( !preg_match("/^\d{6}\-\d{4}$/"$pnr) ) {
            return false;
        }
        $pnr str_replace("-"""$pnr);
        $n 2;
        for ($i=0$i<9$i++) {
            $tmp $pnr[$i] * $n;
            ($tmp 9) ? $sum += + ($tmp 10) : $sum += $tmp; ($n == 2) ? $n $n 2;
        }
     
        return !( ($sum $pnr[9]) % 10);
    }?>

       

    PHP code order form style validate div
  • Profile Image
    JotForm Support

    Answered by ashwin_d on January 18, 2015 at 10:57 PM

    Hello,

    I am not sure if the PHP script you have added above is valid to check the correct format of Swedish SSN number.

    Please be noted that it is anyway not possible to add any custom script code in form editor. You will have to download your forms' full source code and then add the required script to do the validation.

    For your requirement, I will suggest you to add custom JavaScript code to do the validation in your form's full source code. You may like to check the following URL for a sample JavaScript code:  http://stackoverflow.com/questions/7689535/jquery-validation-with-ssn-regex-masked-input-and-depends 

    Hope this helps.

    Do get back to us if you want us to further help you on adding custom JavaScript code and we will surely help you.

    Thank you!