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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:38:57+00:00 2026-06-04T05:38:57+00:00

I have a form I’m trying to do validation on. Requirements state that underscore

  • 0

I have a form I’m trying to do validation on. Requirements state that underscore and hyphen are allowed in the email username, but NO special characters (including hyphen and underscore) are allowed as the leading and/or trailing character of the email username.

Would this be done using regex in the form validation? Or would it be done in a separate jquery function? I’m trying to fire an error in the case that a special character is used as the first or last character of the email username.

Here’s my validation code for the email field:

email: function(value, element) {
        // contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
        return this.optional(element) || /^((([a-z]|\d|[\-\_]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[\-\_]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i.test(value);
    },

And here’s the code for the registration form validation:

if (form == 'registration') {
    var validation_rules = {
        rules: {
            password_confirm: {
                equalTo: "#password"
            },
            email: {

            },
            email_confirm: {
                equalTo: "#email"
            },
            dd_reg_month: "required"
        },
        groups: {
            birthday: "dd_reg_month dd_reg_year"
        },
        errorPlacement: function(error, element) {
            if (element.attr("name") == "dd_reg_month" || element.attr("name") == "dd_reg_year") $("#reg_birthday").append(error);
            else error.insertAfter(element);
        },
        validClass: "success",
        success: "success",
        focusInvalid: false,
        invalidHandler: function(form, validator) {
            var errors = validator.numberOfInvalids();
            var ipAddress =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
                if (errors) {
                    var message = errors == 1 ? 'Please correct the error below' : 'Please correct the ' + errors + ' errors below.';
                    $("div.error_info").html(message);
                    $("div.error_info").show();

                } else {
                    $("div.error_info").hide();
                    $('form input.success').css('border-color', 'green');
                }
        },
        ignore: ".ignore"


    };
}

Any help, even a clue as to how to deal with leading and trailing characters, would be totally awesome.

  • 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-04T05:38:58+00:00Added an answer on June 4, 2026 at 5:38 am

    thanks for the contribution guys! I found some regex that did the trick – this site is really helpful: http://regexlib.com/DisplayPatterns.aspx

    The pattern I used was this, posted by Rob Eberhardt:

    ^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$
    

    Figured I’d share in case anyone comes across the same problem. Check out the regex library if you need to do other things with email validation, it’s got a lot of great patterns. I’m new to regex and hadn’t heard of it yet until today. 🙂

    Thanks again!

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

Sidebar

Related Questions

I have form that I want people to fill out but if they are
I have form for file uploading in my website that i check mime-type of
I have form with dateTimeField, and ListView. ListView looks like that: final ListView<String> countryView
I have form object that I set to request in GET request handler in
I have form data that I insert into a database when the user clicks
I have form with two buttons having same name but different values ,how to
I have form with few text boxes which goes through validation (both server and
I have form on my page that has the following code <form class=form> ...
Let's say I have form A that contains a panel (with many other controls
I have form that displays several keywords (standard set of choice lists that changes

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.