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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:52:28+00:00 2026-05-25T22:52:28+00:00

In my app I let users select a username, just like the twitter signup

  • 0

In my app I let users select a username, just like the twitter signup page: https://twitter.com/signup

When the user starts typing a username, I want in real-time to let the user know if the username is available & valid.

The regex I’ve been using to validate the username is alphanumeric is:

/^[a-z0-9]+[-a-z0-9]*[a-z0-9]+$/i

Given params[:username]

In the controller, how can I validate if the username is alphanumeric or not. Note, I’m not saving the record here just validation. so a model validation wouldn’t work.

Ideas? Thanks

  • 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-05-25T22:52:29+00:00Added an answer on May 25, 2026 at 10:52 pm

    You’d still want to use model validations.

    Something like this perhaps:

    class User
      validates :username, :format => { :with => /your regex/ }, :uniqueness => true
    end
    
    # then in some controller action or rack app
    def test_username
      user = User.new(:username => params[:username])
    
      # Call user.valid? to trigger the validations, then test to see if there are 
      # any on username, which is all you're concerned about here.
      #
      # If there are errors, they'd be returned so you can use them in the view,
      # if not, just return success or something.
      #
      if !user.valid? && user.errors[:username].any?     
        render :json => { :success => false, :errors => user.errors[:username] }
      else
        render :json => { :success => true }
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my rails app I'd like to let users submit custom themes to display
In my app i need to use something that will let the user select
I am developing a chatting/messaging app and I want to let the user select
In my app I'm using a spinners to let the user select an item
In my app i let the user select one image from the media gallery.
So my app needs to let users generate random alphanumeric codes like A6BU31, 38QV3B,
I have a menu that let's a user select a country. Exactly like that
So I'm working on this site web app that should let users easily chat
I want to let the users of my app, which is in turn an
I want to build a flash app to let me and my users snap

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.