Comments (4)
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.
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:
from expressiveannotations.
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.
Awesome! this works exactly the way i want it to.
from expressiveannotations.
Related Issues (20)
- ValueParser doesn't generate *-parsersmap attribute when declared in Metadata
- RequiredIf Attribute not working - 2.7.4 HOT 1
- ExpressiveAnnotation Conflict with Jquery datepicker HOT 1
- Client-side validation: AssertThat vs Kendo NumericTextBox
- AssertThat on a property named "Date"
- RequiredIf error message support with shared localizer(for multi-language) in MVC project HOT 1
- AssertThat always ignored HOT 1
- AssertThat with mathematical formulas ignores decimal places
- No more than 27 unique attributes
- ErrorMessage when combining RequiredIf and AssertThat HOT 2
- RequiredIf rule suddenly requiring full namespace
- sporadic event which corrupts ProcessStorage
- Learning ExpressiveAnnotations - RequiredIf doesn't display the error message
- Can this be used with Blazor?
- Content Security Policy (CSP) unsafe-eval
- Concurrent validation using RequiredIfAttribute throws NullReferenceException HOT 1
- Regex copied from moment.js is vulnerable to ReDOS attack
- Setting the default error message
- Blazor Web Assembly Error (.NET Core 8.0)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from expressiveannotations.