cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
990
Views
0
Helpful
3
Replies

How to check if String variable's value conatins only numbers?

Gerry O'Rourke
Spotlight
Spotlight

Hi,

 

Can anyone give a simple example of checking if a variable string contains only numbers (for UCCX Script editor)?

I was unable to get "isNumeric" to work.

 

Gerry

1 Accepted Solution

Accepted Solutions

Anthony Holloway
Cisco Employee
Cisco Employee

I don't see isNumeric in the list of available methods for a String object.  Where did you come up with that?

 

https://docs.oracle.com/javase/7/docs/api/java/lang/String.html

 

With the available methods in the Script editor drop down of Methods for Strings, ?.matches() seems to do the trick pretty easily:

 

Set test = "123"
If (test.matches("[0-9]+"))
  True
    /* This string looks like an int */
  False

 

Though, this isn't going to match a float/double types.

View solution in original post

3 Replies 3

Anthony Holloway
Cisco Employee
Cisco Employee

I don't see isNumeric in the list of available methods for a String object.  Where did you come up with that?

 

https://docs.oracle.com/javase/7/docs/api/java/lang/String.html

 

With the available methods in the Script editor drop down of Methods for Strings, ?.matches() seems to do the trick pretty easily:

 

Set test = "123"
If (test.matches("[0-9]+"))
  True
    /* This string looks like an int */
  False

 

Though, this isn't going to match a float/double types.

Anthony,

 

Thank you very much. Tested and it works lovely.

Below is the IF node checking my variable "myStringVariable"

 

StringIsNumber.png

I'm glad it helped. Why do you wrap the whole expression in parenthesis? Is it because of my example? If so, I was only doing that to illustrate how it looks after you enter the expression, not that it's a part of the expression. Sorry for the confusion.
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: