how can we validate the website url's by using the regex.
Url's like this:
google.com
www.google.com
here is we want only support above link. if we enter junk data like www://abc, abcdefg like this are not allowed.
I have tried like this in Drupal:
Here is drupal custom code:
$form['web_url'] = array(
'#title' => 'Web URL :',
'#type' => 'textfield',
'#size' => 100,
'#default_value' => @$sourcepath,
'#required' => TRUE,
'#maxlength' => 100,
'#attributes' => array('class' => array('myclass_edit')),
);
function edit_files_form_validation($form, &$form_state){
$website_url = $form_state['values']['web_url'];
drupal_set_message("hi");
drupal_set_message($website_url);
if(!preg_match("/^(http[s]?)\:\/\/([aZ09-_]*?\.)?([aZ09-_]{2,}\.)([\w\.]{2,5})$" ,$website_url )){
form_set_error('web_url',t('Please use only an valid URL links'));
}
}
But not working as my requirement.