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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:57:53+00:00 2026-06-11T02:57:53+00:00

I having some trouble validating some fields with javascript. I’m trying to test a

  • 0

I having some trouble validating some fields with javascript. I’m trying to test a field called name of 30 characters max, John Smith, Paul M’Dougall Laura-Jane should all test true but gazz8932 should test false.

The EAID should be up to 16 characters 123kjg-34_dfs should test true but wil *&$ etc it should test false.

Finally the url should be from youtube.com or ea.com but I can’t bet any of these to work.

If any light can be shed it would be much appreciated…

// create the errors array
var errors = false;

// clean last errors
$('#goalsubmission p.error').remove();
$('#goalsubmission .error').removeClass('error');

// test the name
var reg = /^[a-z ,.'-]{0,30}/i;
var name = $('#goalsubmission input#name');
if(reg.test(name.val()) == false){
    name.parent().addClass('error');
    errors == true;
    name.parent().append('<p class="error">Make sure you have put your name using only letters and spaces.</p>');
} else {
    name.parent().removeClass('error');
}

/*
// test the email
var reg = /(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/;
var email = $('#goalsubmission input#email');
var result = reg.test(email.val());
if(email.val().length == 0 || result == false){
    email.parent().addClass('error');
    errors == true;
    email.parent().append('<p class="error">Make sure you have entered a valid email address.</p>');
} else {
    email.parent().removeClass('error');
}
*/

// test the ea id
var reg = /^[a-z0-9-_]{0,16}/i;
var eaid = $('#goalsubmission input#eaid');
if(reg.test(eaid.val()) == false){
    eaid.parent().addClass('error');
    errors == true;
    eaid.parent().append('<p class="error">Make sure you have entered a valid EAID.</p>');
} else {
    eaid.parent().removeClass('error');
}

// test the url
var regYT = /^http:\/\/(?:www\.)?youtube.com\/watch\?v=\w+(&\S*)?$/
var regEA = /^http:\/\/(?:www\.)?ea.com\/?$/
var url = $('#goalsubmission input#url');
if(
//                          url.val().length == 0 || 
//                          url.val().length > 255  || 
    (regYT.test(url.val()) == false && regEA.test(url.val()) == false)
){
    url.parent().addClass('error');
    errors == true;
    url.parent().append('<p class="error">Make sure you have entered a valid Url, from either YouTube or EA.</p>');
} else {
    url.parent().removeClass('error');
}
  • 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-11T02:57:54+00:00Added an answer on June 11, 2026 at 2:57 am

    You need to mark the regex with $ at the end, so that it doesn’t match anything further from the expression. This way, you’ll match "Paul", but not "Paul123" with the following expression:

    var reg = /^[a-z ,.'-]{0,30}$/i;
    

    Same thing happens with eai:

    var reg = /^[a-z0-9-_]{0,16}$/i;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'll admit, I'm an XML newbie. I'm having trouble validating some xml against a
Having some trouble with this code. Trying to return a tuple of tuples (coordinates)
I having some trouble trying to figure out how to implement a Rails 3
I'm doing some form validation, and I'm having trouble with what I'm trying to
I'm having some trouble getting NHV to work with Fluent NHibernate. A unit test
Hey having some trouble trying to maintain transparency on a png when i create
Having some trouble selecting class names with plain 'ol vanilla javascript: var email =
I'm having trouble with some Excel data validation. On one sheet, I have a
Having some trouble with R's garbage collection, when passing objects to C++. We have
Having some trouble getting a screenscraper webservice up and running on a weblogic 10.3.3

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.