SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: 2,4,6 etc.

  1. #1
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    2,4,6 etc.

    Hi,

    I can't think of the English word for what I'm looking for, which makes it difficult to search for topics, but I hope someone can point me in the right direction

    I have two numbers from a form and I want to validate the input. Let's call the numbers X and Y. Y is input from the user.

    Let's say X is 2, then Y must be 2,4,6,8,10,12 or 14 etc.
    If X is 3 then Y must be 3,6,9,12 or 15 etc.

    How can I validate this?

  2. #2
    SitePoint Addict
    Join Date
    Mar 2007
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if y % x == 0

    Should work if I have understood the problem. Modulo (%) is the remainder of a division. If the remainder is 0 then y was a multiple of x.
    http://www.glasys.co.uk
    Noli Illegitimi Carborundum

  3. #3
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That was exactly what I was looking for. It works great
    Thanks!


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
  •