Want to validate if the last character of a field is '+'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2016 03:11 AM
Hi,
I want to validate if the last character of a field is '+' sign or not.
How can I achieve that?
Thanks and Regards,
Chandra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2016 03:16 AM
if(a.charAt(a.length-1) != '+'){
alert('Message') ;
return false ;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2016 03:20 AM
This would do it:
var str = "Hello world!-";
var res = str.substring(str.length-1, str.length );
if(res == '+')
alert( 'we got a +');
else
alert('no +...');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-23-2016 03:22 AM
slice(-1) function returns the last character of a string.
Example:
var sd = g_form.getValue('short_description');
alert(sd.slice(-1));
You can get the last character of the string and compare it is "+" or not.
Thanks,
Mihir