how to check given input integer or not

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • satya511
    New Member
    • Nov 2016
    • 1

    how to check given input integer or not

    I can take (id-Integer in model class) input from spring form ,how to check whether integer or not
    output -suppose I gave input integer format con't show any error , but gave string format it can show error
    Failed to convert property value of type java.lang.Strin g to required type java.lang.Integ er for property id; nested exception is java.lang.Numbe rFormatExceptio n: For input string: "dfgrgf"
    Employee id required or Employee Id greater than 0
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    You can check with regular expressions if the string conforms to "\d+". If it does, then it is an integer.
    But you need to tell us more. Do you also need to check for negative integers?
    Is the integer length limited to10 chars?
    Do you need to trim white spaces before/after the integer away?
    If all yes, you can check with the regEx "\s*[+-]?\d{1,10}\s*".

    Comment

    Working...