Code Monkey home page Code Monkey logo

Comments (4)

okankocyigit avatar okankocyigit commented on July 22, 2024

I think you just implement the server-side validation and looking for client side validation.

As it mentioned in docs, you also have to add client side validation method to get it work properly.

ea.addMethod('IsValidCanadianSIN', function (sin) {
       return /^(\d{3}-\d{3}-\d{3})|(\d{9})$/.test(sin);
});

from expressiveannotations.

dkhalil1994 avatar dkhalil1994 commented on July 22, 2024

Thank you for your reply, it works perfectly on client side, however is there any way to make this validation work on the server side only.
Since i have to fine tune a method for validation and i don't want to have it implemented in jquery.
Here is my method:

public static bool IsValidSIN(string SIN)
{
String wNAS = SIN.Replace(" ", "");
String wNASMult = "121212121";
int wMult;
int wSumMult = 0;

        if (wNAS.Length < 9)
        {
            return false;
        }

        for (int i = 0; i < wNAS.Length; i++)
        {
            wMult = Convert.ToInt32(wNASMult.Substring(i, 1)) * Convert.ToInt32(wNAS.Substring(i, 1));
            if (wMult > 9)
            {
                string wTmp = wMult.ToString();
                wSumMult += Convert.ToInt32(wTmp.Substring(0, 1)) + Convert.ToInt32(wTmp.Substring(1, 1));
            }
            else
            {
                wSumMult += wMult;
            }
        }

        return (wSumMult % 10) == 0;
    }

This is what my Global.asax file looks like, i have commented out the code to enable client side validation:

image

from expressiveannotations.

okankocyigit avatar okankocyigit commented on July 22, 2024

you can disable client-side validation for that specific field,

@Html.TextBoxFor(model => model.SIN, new { data_val="false" })

But this also disables other validations which might work client-side like required.

To avoid this, you can just return true from custom client-side validation method, so it will always pass client-side validation.

ea.addMethod('IsValidCanadianSIN', () => true)

from expressiveannotations.

dkhalil1994 avatar dkhalil1994 commented on July 22, 2024

Awesome! this works exactly the way i want it to.

from expressiveannotations.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.