Check if command arg contains invalid character

Discussion in 'Plugin Development' started by goldencreeper, Sep 19, 2012.

Thread Status:
Not open for further replies.
  1. Offline


    How would i check if a command argument contains only numbers?

    if a player types /cbb 456 it will do the rest of the code.

    if a player types /ccb @34gdg#$b8 it will send the player a message saying "Invalid Characters"

    I only want the command to continue to read the rest of the code if it only contains numbers

  2. Offline


    if(arg[x].matches(".*[1-9].*") == true)
    //your code
    should work , else goggle after "java regex" :)
  3. Offline


    wouldnt that try to see if it matches anything because of the .*?
  4. Offline


    If you're trying to get it as a number value anyway, it might be easier to do this:
    try {
        int n = Integer.parseInt(arg[x]);
        //your code
    } catch (NumberFormatException e) {
        //not a valid number
  5. Offline


    No , it would only check if in the String Contains only the numbers any where :)

    yeah sure that would work too but I dont like try/catch :eek:
  6. Offline


    if(arg[x].matches(".*[1-9].*") == true) that does work but it doesnt detect specials Chars like: !@#$%^&*() ...etc
  7. Offline


    then do it with try catch ^^ I dont know which was the operator for this :p
  8. Offline


    Why on earth not? It's the right way to do it.
Thread Status:
Not open for further replies.

Share This Page