Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7854169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:58:16+00:00 2026-06-02T19:58:16+00:00

In my model I have a particular field that is annotated in the following

  • 0

In my model I have a particular field that is annotated in the following manner:

    [DataType(System.ComponentModel.DataAnnotations.DataType.Text)]
    [RegularExpression("[0-9]{1,10}", ErrorMessage = "The stated Attempt Id is invalid!")]
    public long? AttemptId { get; set; }

When I enter incorrect data in the Attempt ID it is giving me the following error message in the Model State:

The value 'cbcbxcb' is not valid for AttemptId.

I have other field with similar error messages but they’re of type string instead of long? and the correct error message is being displayed in those cases when an invalid value is given. Why isn’t the message for the ‘long?’ being used? I’m displaying my errors using the folowing literal tag in the page.

<%: Html.TValidationSummary() %>

EDIT: I have attempted to change the validation in the model to the following:

    [Required(ErrorMessage="The stated Attempt Id is invalid!", AllowEmptyStrings=true)]

This however is still incorrect. Firstly, I need to allow the field to be left empty, and when I do it’s giving me the ‘The stated Attempt Id is invalid!’ error message. Secondly when I do enter invalid data in the field it’s reverting back to its old bad error message.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:58:19+00:00Added an answer on June 2, 2026 at 7:58 pm

    The RegularExpression validation attribute only works with string types. To get a custom error message, use the Required validation attribute instead and put your own custom error message in.

    If your model parameter isn’t mandatory, you could perform the validation within the controller and add your own custom message using the ModelState.AddModelError method – this is a bit of a hack, though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have model Article it has field title with some text that may contain
I have a video model that stores 'likes' as a manytomany field with User.
I have a Post model that has a datetime.date field for posted_date . I
I have model Foo which has field bar. The bar field should be unique,
I have model: # encoding: utf-8 class Tag include Mongoid::Document field :name, type: String
In my business model I have Entity class (IPoint interface ) that has a
I have Django model that looks like this: class Categories(models.Model): Model for storing the
I have the following model set up: class UserProfile(models.Model): Additional attributes for users. url
A common occurrence I have with one particular project is that it requires the
I have comment model that references (foreign key) a post model and there is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.