Create custom validation with three different error messages - asp.net-mvc-4

I need to create a validation on an email field, i am using MVC 4.
I would use a simple regular expression, however as you see below i need to show three different error messages depending of the input on email field.
Validation Rules:
1)If the # sign is not present in the email address, display the message: # sign is required.
2) If no period (.) is entered, display the message: Period (.) after the # sign is required.
3) If 2 characters are not present after the period, display the message: Must contain at least 2 characters after the period.

Related

webcenter content field validation

How can we validate a custom field while checkin in to Oracle WebCenter Content?It may be an email validation or custom validation say the file will allow user to input only 10 chars of which first four are alpha and the next sixth char are numeric.
Regards,
Ananda Roy
Try adding a rule to the profile (or using global rule). Then, in the rule side effect, set this: <$xCustomField:maxLength=10$>
You can get fancier validation by doing more customization such as this.

How to validate the all parametes by using XSD against validation

How to validate the all mandatory parameters at one time.I want to display all mandatory parameters not entered in user .For Example I have 4 parameters username,pwd,phno,address.
If the user not provided the information of two parameters like pwd and address.
By using the XSD against validation concept,It throwing the SAX Exception on PWD.but it not showing the exception on Adress as well.
Condition:
1.Input format may jsonformat,xml,or any thing.
Please share information.
I have not found concrete information from this site.

How to change registration requirement for user ID in chat function

Hi when I run the sample chat function provided by quickblox, it contains several built-in limitation for username registration, for example, I need to have a certain number of characters or type of characters in order to register. I'm wondering which files contain those registration and display of error messages (I only found a class called "errors" in SignUpViewController ) and how do I change those limitations?
There are 2 ways:
Sign Up & then Sign In with email
Sign Up & then Sign In with login - Login field should contain alphanumeric and punctuation characters only
Is it OK? Or you have problem with other User's field?

Rails 3: Modify error message prefix for form validation

Nested forms are great, but I have noticed that it can sometimes lead to error message that are oddly formatted.
To give a concrete example:
I have a form that lets someone create a new Account. Each account has one or more Users (has_many). The signup form uses the Account model for creating the form and also includes a number of fields for creating the first User (as an account must have at least one user). In other words, it is a nested form.
Because an account can have many users, the prefix of the error messages says "users" instead of "user". Also, the error messages use the relationship name (users) and the attribute name (for example, "password") to construct the error message. This results in error message such as "Users email can't be blank." instead of "Email can't be blank.".
Is there a way to customize the error message or omit "users" from the error message?
In your :message parameter of your validation, you can add a caret which will strip the default message.
:message => "^ Email can't be blank"

Rails - How do you stop custom validators from running on optional fields?

I have a model called Client which runs a custom phone number validator to see if a given phone number is valid (validates :phone_number, :run_custom_validator => true). The problem is that this phone number field should not be required, its optional, but the validator runs every time even when no phone number is given. How do I get the validator to run only when a phone number is given? Any responses would be much appreciated! Thanks!
In the custom phone number validator, on the first line put the following:
return if phone_number.blank?