SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Nov 2010
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Nested functions?

    This should be easy but I can not figure this out...

    How do you do a nested function? Here are the snippets...
    if(isAlphabet, trimAll(FirstName, "Please enter your first name")){

    function isAlphabet(elem, helperMsg){
    var alphaExp = /^[a-zA-Z]+$/;
    if(elem.value.match(alphaExp)){
    return true;
    }else{
    alert(helperMsg);
    elem.focus();
    return false;



    Everything worked with my code but I was having a hard time submitting a form with more then one word in the text box. So I found this code...but can not figue out how to have the if statement to do both functions. Can you help, please?

    Here's the spaces function...

    function trimAll( strValue ) {
    var objRegExp = /^(\s*)$/;

    //check for all spaces
    if(objRegExp.test(strValue)) {
    strValue = strValue.replace(objRegExp, '');
    if( strValue.length == 0)
    return strValue;
    }

    //check for leading & trailing spaces
    objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
    if(objRegExp.test(strValue)) {
    //remove leading and trailing whitespace characters
    strValue = strValue.replace(objRegExp, '$2');
    }
    return strValue;

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if(isAlphabet, trimAll(FirstName, "Please enter your first name")){
    You call a function by nameoffunction(parameter1, parameter2). So above should be

    Code JavaScript:
    if (isAlphabet(trimAll(FirstName), "Please enter your first name") {

    That is call trimAll with a parameter FirstName and call isAlphabet with a first parmeter the result of the trimAll function and a second parameter the string.


Bookmarks

Posting Permissions

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