on 02-08-2013 9:25 PM
Hello Everyone,
I was wondering if there is any function in MII to check if the given string is a valid number . The closest that I can get is "number(string)" function which converts the the I/P string to a number or throws a exception if the I/P is not a valid number . I am looking for some which returns me 0 or 1 based on the I/P value .
(sth like "numbercheck(string,0,1)"; )
Thanks,
Naresh Agarwal,
RegEx can do this task in a very efficient way.
Try this in expression editor: match("1234","^[0-9]+$")
Thanks
Hari
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Naresh,
1. There is no direct function in MII to check if the string is number or not. However, as Hari mentioned, you can use match() and pass a regex to check ur case.
For example, if you only have an integer, then Hari's regex pattern works very well
match("1234","^[0-9]+$") ==> 0, false- 1, true
If you have decimal notation too, then try using this pattern
match("14.0", "^([+-]?\\d*\\.?\\d*)$") ==> 0, false- 1, true
2. The number(string) function, you tried would only throw exception if the entire string is a string say "abcd", if you pass "12abcd12", then the function would return you 12.
3. The other method is to use a local variable of type integer/float/double and try assigning the value to it . If an invalid value like abcd is assigned to the variable, then a DataConversionException would be thrown. I guess you can catch(catch action block) this and apply your business logic if needed.
Regards,
Tufale Ashai.
This message was moderated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Naresh,
The function number() returns the actual number if a numeric value is passed to it and returns NA if a string is passed to it provided the value to be passed to this function should be passed without double quotes.
Further, to fulfill your requirement you can use stringif(number(VALUE) == "NA",0,1).
Hope this helps.
Regards,
Anuj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
12 | |
7 | |
3 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.