SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    bahrain
    Posts
    553
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up only allowing numbers

    hi

    iw ant to have a function so that user can only enter numbers in the text box and + ( only once in the beggininging). if user wants to add + he can only enter + once as the first character like +123 or 123 bt cannot enter 1+2 or 123+ or +123+
    its urgent plzzz.....
    regards
    phphelp

  2. #2
    SitePoint Evangelist vikrantkorde's Avatar
    Join Date
    Jun 2004
    Location
    Mumbai, India
    Posts
    541
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use this
    [\+]?[0-9]+
    Vikrant Korde
    S Y S T I M E, Mhape,
    Mumbai, Maharashtra, India.

  3. #3
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    bahrain
    Posts
    553
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    soeey vikrant, i did not understand. please explaina bit how could i use it in function???????? plesae give me some example....
    its urgent plzzz.....
    regards
    phphelp

  4. #4
    SitePoint Evangelist vikrantkorde's Avatar
    Join Date
    Jun 2004
    Location
    Mumbai, India
    Posts
    541
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is the code
    Code:
     function checknumber(field,title)
     {
     var value=field.value;
     var pattern=/^[\+]?[0-9]+$/;
     var result='';
     result=pattern.exec(value);
     if (value=="")
     	{
     	value=null;
     	}
     if (result!=value)
     	{
     	alert ("Sorry, "+title+" is invalid.\nPlease do not use Alphabets or Special Characters. Use only numbers");
     	field.focus();
     	field.select();
     	return false;
     	}
     else
     	{
     	return true;
     	}
     }
    use this function in the onSubmit function or onBlur event.

    in Aruguments field is the object of the field that holds the value.
    title is the string holding the name of the field. used for alert only.
    Last edited by vikrantkorde; Jul 24, 2006 at 21:05. Reason: The reguallar expression was corrected as per the requirement.
    Vikrant Korde
    S Y S T I M E, Mhape,
    Mumbai, Maharashtra, India.

  5. #5
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    bahrain
    Posts
    553
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually i want also to restrict the user on the run not been able to enter any other character only + and 0 to 9 and only + the first character?????
    its urgent plzzz.....
    regards
    phphelp


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
  •