phone number validations which is 8 digits character's limit ,it will allow only numbers (will not allow other charters like Special symbols @,\$,A..)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2017 07:43 AM
Hi Friends,
phone number validations which is 8 digits character's limit ,it will allow only numbers (will not allow other charters like Special symbols @,$,A..) .can any one give me sample code.
Thanks in Advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2017 08:47 AM
Hi Padhu,
I tried the below code and it worked for me.
Script: OnChange.
function onChange(control, oldValue, newValue, isLoading) {
if(isLoading || newValue == ''){
return;
}
var pattern = /^[0-9]*$/;
if(!pattern.test(newValue) || (newValue.length <= 7) )// adjust your digits.
{
alert('please enter only digits and min length should be 8 ');
g_form.setValue('upc', ''); // adjust field name accordingly if you want to blank it out.
}
}
Regards,
Sampath.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2017 08:49 AM
Does it also work with ABCDEFGH...? By the looks of your tests, that would also be permitted...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2017 08:53 AM
The script which I mentioned will not allow any alphabets to be entered.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2017 12:57 PM
I'm surprised, since * means zero2many... but I just tried it in https://regex101.com/ and can confirm it works as intended!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2017 01:37 PM
Assuming this comment is intended for me the * is indeed an indicator of zero to many occurrences. But in the following line of code: if(!regex.test(newValue) || newValue.length != 8), I'm checking the length of the newValue. That's why it works.