简体   繁体   中英

iframe Regular Expression form validation

I'm having trouble validating a form entry using a regular expression. I am only just learning regular expressions and specifically for this task.

The problem: I have attempted to write a regex that would match a soundcloud iframe. However, the form entry is accepted whether the entry is a soundcloud iframe or not. Any help would be much appreciated!

This is the function I came up with:

function iframe_match ($iframe){
return(preg_match('#/<iframe width="100%" height="450" scrolling="no" frameborder="no"     src="https://w.soundcloud.com/player/\?url=http%3A%2F%2Fapi.soundcloud.com%2F|[a-z]|%|[0-9]|    [F]|">\</iframe\>/#', $iframe)) ? true : false;
}

And this is the specific form check:

else if (iframe_match($_POST['track_file1']) === false){
echo '<br/><br/><font color="red"><strong>Must include an iframe</strong><font>'; 
 }
function iframe_match ($iframe){
return(preg_match('/<iframe[^>]*src="https:\/\/w.soundcloud.com\/player\/[^"]+">\s*<\/iframe>/',$iframe)) ? true : false;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM