www.webdeveloper.com
Results 1 to 5 of 5

Thread: code required

  1. #1
    Join Date
    Jul 2013
    Posts
    4

    Post code required

    MTSU uses course specifications like CSCI 4410-001. Here is a partial list of syntax rules for a MTSU course specification:
     It starts with from 2 to 4 uppercase letters
     Next comes a space
     Next comes a 4-digit number
     Next comes a hyphen (-)
     Next comes a section number which is either a 3 digit number, or the letter H or L followed by a two digit number
    Write a JavaScript function isCourse with one parameter, a string. It will return true if the string represents a MTSU course specification according to the above rules and false otherwise. You must use pattern matching appropriately. To test this function, write a simple HTML file containing a text box that will receive the course name and a submit button. On submit, the isCourse function should be used to determine whether the course is valid or not with an appropriate message in either case.

    Can you please write the code explanation as well to help me understand it better. Thanks

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,406
    Hmmmm, this is very homeworky

    Looking at the question you need a form, the form submit option onSubmit="" needs a function called isCourse

    Suggest that the function isCourse is written so it returns a value of true or false so when using it in the form onSubmit="return isCourse(this);" will cause the form to submit if true or if not true the form submit is ceased.

    passing the generic object this will allow you to address the specific field you need to test in the form submit as "this" will be all the forms inputs and options lists, etc.

    Your HTML file should contain your validation script and the form that you are going to use / validate.
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  3. #3
    Join Date
    Nov 2002
    Location
    Flint, Michigan, USA
    Posts
    598
    Start with this and figure it out:
    Code:
    I=prompt('Input','');
    if (I.match(/^[A-Z]{2,4}\ [0-9]{4}\-([0-9]{3}|H[0-9]{2}|L[0-9]{2})$/)) {
      alert('OK');
    } else {
      alert('-nope-');
    }

  4. #4
    Join Date
    Jan 2014
    Location
    Pakistan
    Posts
    6
    I=prompt('Input','');
    if (I.match( /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/)) {
    alert('OK');
    } else {
    alert('-nope-');
    }
    This is the way I used the email verification code in my project.

  5. #5
    Join Date
    Mar 2012
    Posts
    202
    Quote Originally Posted by jalarie View Post
    Start with this and figure it out:
    Code:
    I=prompt('Input','');
    if (I.match(/^[A-Z]{2,4}\ [0-9]{4}\-([0-9]{3}|H[0-9]{2}|L[0-9]{2})$/)) {
      alert('OK');
    } else {
      alert('-nope-');
    }
    ... this is why incompetent programmers are getting all the jobs (because the competent keep allowing them to use their work)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles