Search code examples
javascriptvimeo

How to validate Vimeo video id?


I need to create a regular expression which could validate a valid Vimeo video.

Accordingly to Vimeo API they use only numbers for Video Id, but they do not specify the length.

My regular expression so far var regEx= /^[0-9]+$/;

I would like to know: - What is the allowed length supported by vimeo video id? - How to modify my regEx?

Only article I found: https://vimeo.com/forums/topic:267078


Solution

  • Instead of trying to invent a Vimeo Video ID validator, why don't you just use the Vimeo developper API to check if the Vimeo ID is valid?

    GET https://api.vimeo.com/videos/{video_id}
    
    +------------------+--------------------------------------------------+
    | Http Status Code | Explanation                                      |
    +------------------+--------------------------------------------------+
    | 200 Ok           |                                                  |
    +------------------+--------------------------------------------------+
    | 403              | if the video does exist, but the view or the app |
    |                  | requesting the video resource does not have      |
    |                  | permission to access that video.                 |
    +------------------+--------------------------------------------------+
    | 404 not found    | If the video cannot be found.                    |
    +------------------+--------------------------------------------------+ 
    

    Check if you (1) or a user (2) owns a video:

    (1) GET https://api.vimeo.com/me/videos/{video_id}
    (2) GET https://api.vimeo.com/users/{user_id}/videos/{video_id}
    
    +------------------+------------------------------------------------------+
    | Http Status Code | Explanation                                          |
    +------------------+------------------------------------------------------+
    | 200 Ok           |                                                      |
    +------------------+------------------------------------------------------+
    | 404 not found    | If the video is not owned by the authenticated user. |
    +------------------+------------------------------------------------------+