Vimeo Video Url Validate using Regular Expressions in ASP.Net

mukesh1
 
on Jun 08, 2022 02:25 AM
Sample_140817.zip
513 Views

Valid regex for vimeo video url.

http://www.vimeo.com/1234
https://www.vimeo.com/1234
https://player.vimeo.com/video/30572181

 

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Jun 10, 2022 12:01 AM
on Jun 10, 2022 12:04 AM

Hi mukesh1,

Vimeo have below different types video links.

Video -  vimeo.com/VideoId

Channels -  vimeo.com/channels/Channel/VideoId

Groups -  vimeo.com/groups/Group/VideoId

Player -  player.vimeo.com/video/VideoId

Use below RegularExpression for validate the url.

(?:http|https)?:?\/?\/?(?:www\.)?(?:player\.)?vimeo\.com\/(?:channels\/(?:\w+\/)?|groups\/(?:[^\/]*)\/videos\/|video\/|)(\d+)(?:|\/\?)

Refer below example.

HTML

<asp:TextBox ID="txtUrl" runat="server" />
<asp:Button Text="Validate" runat="server" OnClick="OnValidate" />

Code

C#

protected void OnValidate(object sender, EventArgs e)
{
    System.Text.RegularExpressions.Regex regx = 
        new System.Text.RegularExpressions.Regex(@"(?:http|https)?:?\/?\/?(?:www\.)?(?:player\.)?vimeo\.com\/(?:channels\/(?:\w+\/)?|groups\/(?:[^\/]*)\/videos\/|video\/|)(\d+)(?:|\/\?)");
    System.Text.RegularExpressions.Match match = regx.Match(txtUrl.Text.Trim());
    if (match.Success)
    {
        ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + txtUrl.Text.Trim() + " is valid');", true);
    }
    else
    {
        ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + txtUrl.Text.Trim() + " is invalid');", true);
    }
}

VB.Net

Protected Sub OnValidate(ByVal sender As Object, ByVal e As EventArgs)
    Dim regx As System.Text.RegularExpressions.Regex =
        New System.Text.RegularExpressions.Regex("(?:http|https)?:?\/?\/?(?:www\.)?(?:player\.)?vimeo\.com\/(?:channels\/(?:\w+\/)?|groups\/(?:[^\/]*)\/videos\/|video\/|)(\d+)(?:|\/\?)")
    Dim match As System.Text.RegularExpressions.Match = regx.Match(txtUrl.Text.Trim())
    If match.Success Then
        ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alert('" & txtUrl.Text.Trim() & " is valid');", True)
    Else
        ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alert('" & txtUrl.Text.Trim() & " is invalid');", True)
    End If
End Sub

Screenshot