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

  • Home
  • SEARCH
  • 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 8586891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:25:39+00:00 2026-06-11T22:25:39+00:00

Is it possible to validate that a Character is either M or F or

  • 0

Is it possible to validate that a Character is either M or F or do I need to use a string with a regex?

@Pattern(regexp = "^[MF]{1}$", message = "customer.sex.regex")
private String sex;

I would like to use

private Character sex;
  • 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-11T22:25:40+00:00Added an answer on June 11, 2026 at 10:25 pm

    Your should this regular expression for accepting only M or F.

    @Pattern(regexp = "^[M|F]{1}$", message ="Must be M or F")
    

    In your second case of using as Character, you need to validate that this character is whether “M” or “F”. Other can be set as sex.

    You cannot use @Pattern for Character variable, You will get below exception.

    javax.validation.UnexpectedTypeException: HV000030: No validator could
    be found for type: java.lang.Character.

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

Sidebar

Related Questions

Is it possible to use a RegEx to validate, or sanitize Base64 data? That's
Is that possible to pass variable into regular expression pattern string in jquery (
I have a string that I would like to validate a certain pattern for:
Possible Duplicate: RegEx to make sure that the string contains at least one lower
I'm trying to use validation in Spring.NET to validate that a string property of
I need make a regex expression to validate an external string. I'm building a
I'm just wondering if it's possible to validate or check that at least one
With FluentValidation, is it possible to validate a string as a parseable DateTime without
I have a textarea in which I need to validate that at least one
I want to use ComponentModel DataAnnotations validate that at least one of two properties

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.