- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2015 07:00 AM
Hi All,
I have the following onSubmit() script that checks to see if a field contains :// and if so, stops the form from being saved and displays a pop-up.
function onSubmit() {
var name = g_form.getValue('name');
var altname = g_form.getValue('u_alternative_name');
if (name.indexOf('://') > -1 || altname.indexOf('://') > -1) {
alert('Please enter only the domain without any prefix');
g_form.submitted = false;
return false;
}
}
I have now been asked to amend the script to check if a , (comma) has been entered?
Any ideas on how to do this? Should i create an array of the letters, symbols that i want to search for?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2015 07:19 AM
Hi Alex, since you're only checking for only two type of characters, I will perhaps keep it simple. If it grows above 4 type of characters, then you probably want to think in a different approach.
if (name.indexOf('://') > -1 || altname.indexOf('://') > -1 || name.indexOf(',') > -1 || altname.indexOf(',') > -1) {
alert('Please enter only the domain without any prefix');
g_form.submitted = false;
return false;
}
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2015 07:19 AM
Hi Alex, since you're only checking for only two type of characters, I will perhaps keep it simple. If it grows above 4 type of characters, then you probably want to think in a different approach.
if (name.indexOf('://') > -1 || altname.indexOf('://') > -1 || name.indexOf(',') > -1 || altname.indexOf(',') > -1) {
alert('Please enter only the domain without any prefix');
g_form.submitted = false;
return false;
}
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2015 07:27 AM
Works perfectly.