This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I am wanting to catch an invalid email address closer to the UI - before it gets into the lightspeed model. How can I use the lightspeed email validation logic elsewhere in my code - so I can gaurantee that by the time I validate my entity, I know the email address will be okay. Also - is there a RegEx that you use (that would be handy as then I can just use a RegEx validator). Thanks! |
|
|
Interesting question! It turns out that there's no way to invoke a LightSpeed ValidationRule from your own code, because ValidationRule.Validate requires a ValidationContext and you can't produce one of those outside LightSpeed. We do just use a regex -- a fairly simple one which you are welcome to reuse: private const string EmailValidationRegEx = @"^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$"; This is probably the best solution though it does mean that if LightSpeed later changes its regex then your UI will be out of sync. In practice though we are only likely to make the regex more liberal, so you still won't hit the 'UI validates, LightSpeed rejects' problem. Note that LightSpeed email validation permits null or empty strings unless the validation is marked IsRequired=true, so you may need to handle that case as well. If for some reason you need to guarantee absolutely consistency by reusing the LightSpeed rule, you could do a hack of declaring a dummy entity class with a single property that has email validation applied to it: then to validate a string you'd copy the string into a dummy entity instance, call Validate and see whether it passed. This would be shameful though... |
|
|
Truly shameful... Thanks Ivan. Will use the Regex as you suggested! Am still stunned at the speed of your support responses - there is no other vendor out there that give such helpful and FAST responses to queries. Keep up the great work! |
|
|
Thanks for the kind feedback Rodney :-) Do you mind if we use that as a testimonial in our marketing? Cheers, John-Daniel |
|