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 8083393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:27:22+00:00 2026-06-05T17:27:22+00:00

How do I set a value to only accept certain data in Python ?

  • 0

How do I set a value to only accept certain data in Python? Like I am making a code for a colour identifier. I want my variable to only accept up to FFFFFF any nothing greater than that. The base-16 characters pretty much…hex code.

The reason I am trying to do this is because if a user enters in a value like GGGGGG it will give them a Script Error, which actually makes me look incompetent (which I might be, but I do not want to look like I am). And also, if they enter in special characters like F1F2G% it will mess up too. In addition, if they leave the box blank, it also gives a Script Error.

I want to avoid those errors. Does anyone know of a good way?

  • 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-05T17:27:24+00:00Added an answer on June 5, 2026 at 5:27 pm
    try:
        val = int(hex_val, 16)
    except ValueError:
        # Not a valid hex value
    
    if val > int("FFFFFF", 16):
        # Value is too large
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to set up a TextBox to get only certain values. e.g. DateTime input
I want to set the value of Inclusion list for Moderate risk file Types
Every time try to set the value of any variable in my model object,
I'd like to pass a value type to a function and set it to
I'm using this authorization function in my socket.io setup: io.set('authorization', function (data, accept) {
Table having boolean column ,boolean should only accept value 0 or 1 but it
I want a single generic class that can accept either reference or value types,
I need to write a generic procedure that set value for one column or
How could I set the value of the Height property of a WPF control
how do I set the value of a field element after a form has

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.